在一个php foreach中连接数组和字符串变量

时间:2016-02-08 12:19:53

标签: php arrays foreach

是否有可能将2个变量“粘合”为foreach中的变量?我已经尝试过使用dot_combine中的点。都给我错误...... $ courseFiles是一个数组,而$ block [id]是一个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;
?>

1 个答案:

答案 0 :(得分:0)

试试这个:

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

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