Home Ask Login Register

Developers Planet

Your answer is one click away!

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.

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


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


Leave an answer

Quote of the day: live life