我遇到的这个第二次迭代的麻烦,看看下面的代码:如何只获取数据数组的几个索引?
include ('rest.php');
include ('header.php');
include ('topo.php');
include ('menu.php');
$token = $_COOKIE['token'];
$table1 = "<div class='pai-forms'>
<table id='calendarTable'>
<tr>
<th>Posição Array</th>
<th>Nome</th>
<th>Email</th>
<th>CEP</th>
<th>Numero</th>
<th>Complemento</th>
<th>Rua</th>
<th>Logo</th>
<th>Latitude</th>
<th>Longitude</th>
<th>Ativo</th>
<th>Criado</th>
<th>Atualizado</th>
</tr>";
$table2 = " </table>
</div>";
$dataSalons = wsListSalons($token);
echo $table1;
foreach ($dataSalons['data'] as $key => $value) {
echo "<tr>";
for ($i = 1; $i < 6; $i++) { // HERE IS THE PROBLEM
echo "<td>".$value[$key]."</td>";
}
echo "</tr>";
}
echo $table2;
include ('footer.php');
我只是想拿到指标1的数据通过阵列的6,但是当这条线for ($i = 1; $i < 6; $i++)
执行,它引发许多这样的错误:
注意:未定义偏移量:0在C:\ XAMPP \ htdocs中\ mcisalaositeadmin上线\ list_salons.php 39
注意:未定义偏移量:0在C:\ XAMPP \ htdocs \ mcisalaositeadmin \ list_salons.php第39行
注意:Undefin ED偏移:1 C:\ XAMPP \ htdocs中\ mcisalaositeadmin上线\ list_salons.php 39
注意:未定义偏移:1 C:\ XAMPP \ htdocs中\ mcisalaositeadmin \上线list_salons.php 39
我错过了什么? PS:我只是用foreach循环试了一下,它可以工作,但它将所有的索引数据都返回给我。我只想获得索引数据1到6.
就是这样的人! array_slice解决方案,我从来没有见过..这工作完美..非常感谢你.. –
@daniel_serretti不客气。很高兴我能帮助你:D – Rizier123