Domien Ledoux February 2016

concatenate array and string variables in a php foreach

Is it possible to "glue" 2 variabels as one in a foreach? i've tried it with dot inbetween with array_combine. all give me errors... the $courseFiles is an array, while the $block[id] is a int.

<?php
    foreach($courseFiles . $block["id"] as $courseFile): ?>
        <tr>
            <td><?php echo htmlentities($courseFile["Exercise Name"]) ?></td>
            <td><?php echo htmlentities($courseFile["Logsheet"]) ?></td>
            <td><?php echo htmlentities($courseFile["EBF Sheet"]) ?></td>
        </tr>
    <?php endforeach;
?>

Answers


Bilal Sardar February 2016

try this:

$myvar = array();
// assign values to $myvar array.
$myvar[$index] = $courseFiles[$index] . $block["id"]; 

foreach($myvar as $courseFile)
{ //some code }

Post Status

Asked in February 2016
Viewed 2,695 times
Voted 7
Answered 1 times

Search




Leave an answer