[英]iterate over array in php
Ok, so I've read loads of articles and I think I'm at risk of duplicating, but cant work this one out. 好的,所以我读了很多文章,我认为我有重复的风险,但是无法解决。
I have an array that is being returned by a PHP function, I've called it getLeague(); 我有一个由PHP函数返回的数组,我将其称为getLeague();。
The structure of the array is: 数组的结构为:
body[0]->position
身体[0]->位置
body[0]->teamname
正文[0]->团队名称
body[0]->points
正文[0]->要点
and obviously the results increment from 0 -16 as that's the amount of teams in my league. 显然结果从0 -16递增,因为那是我联盟中的球队数量。
I'm trying to tabulate the array by calling getLeague() and iterating over the returned array to print into a table. 我试图通过调用getLeague()并对返回的数组进行迭代以打印到表格中来制表数组。
I'm trying at the minute to work out the basic for each loop, after that I'll shoehorn it into a table. 我正在尝试在每一分钟内制定每个循环的基础,然后将它拔到表中。 Can you help me with the foreach?
您能帮我个忙吗? I've tried:
我试过了:
<table class="table table-striped">
<thead>
<tr>
<th>Position</th>
<th>Team</th>
<th>Points</th>
</tr>
</thead>
<tbody>
<?php
$rows = getLeague();
foreach ($rows as $row):
?>
<tr>
<td><?= $row->body->position; ?></td>
<td><?= $row->body->teamname; ?></td>
<td><?= $row->body->points; ?></td>
</tr>
<? endforeach ?>
</tbody>
</table>
Any help appreciated. 任何帮助表示赞赏。
Without seeing more on that data structure, I can't say for certain, but I think you want: 没有看到更多关于该数据结构的信息,我不能肯定地说,但我认为您想要:
foreach ($rows->body as $row):
And: 和:
$row->position
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.