我有courses
和schools
数组。我想在课程数组中使用学校数组:
<? foreach ($courses as $course) {
<div class="cat_row">
<?= $course['location'] ?>
</div>
<? } ?>
当我使用
<? foreach($schools as $coordinate){
echo $coordinate->latitude;
} ?>
在第一个foreach中,它在每个块中显示所有坐标,如:
|first|second|third|
|1 2 3|1 2 3 |1 2 3|
如何制作as:
|first|second|third|
|1 |2 |3 |
?有人能帮我吗?
如果两个数组中的项数相等,则应该只使用一次foreach
<? foreach ($courses as $key=>$course) {
<div class="cat_row">
<?= $course['location'] ?>
<?= $schools[$key]->latitude ?>
</div>
<? } ?>