[英]iterate over array in php
好的,所以我讀了很多文章,我認為我有重復的風險,但是無法解決。
我有一個由PHP函數返回的數組,我將其稱為getLeague();。
數組的結構為:
身體[0]->位置
正文[0]->團隊名稱
正文[0]->要點
顯然結果從0 -16遞增,因為那是我聯盟中的球隊數量。
我試圖通過調用getLeague()並對返回的數組進行迭代以打印到表格中來制表數組。
我正在嘗試在每一分鍾內制定每個循環的基礎,然后將它拔到表中。 您能幫我個忙嗎? 我試過了:
<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>
任何幫助表示贊賞。
沒有看到更多關於該數據結構的信息,我不能肯定地說,但我認為您想要:
foreach ($rows->body as $row):
和:
$row->position
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.