在 PHP foreach 中连接数组和字符串变量


concatenate array and string variables in a php foreach

是否可以将 2 个变奏曲器"粘合"为一个? 我已经尝试过用点中间的点和array_combine。 都给我错误...$courseFiles是一个数组,而$block[id]是一个整数。

<?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;
?>

试试这个:

$myvar = array();
// assign values to $myvar array.
$myvar[$index] = $courseFiles[$index] . $block["id"]; 
foreach($myvar as $courseFile)
{ //some code }