Php 如何在一个数组中更改数组的多个循环
我当前循环中的数组格式如下所示:Php 如何在一个数组中更改数组的多个循环,php,arrays,codeigniter,Php,Arrays,Codeigniter,我当前循环中的数组格式如下所示: Array ( [0] => Array ( [studentID] => 1 [ParentID] => 1 ) [1] => Array ( [studentID] => 2 [ParentID] => 1 ) ) Array ( [0] => Array ( [studentID] =>
Array (
[0] => Array (
[studentID] => 1
[ParentID] => 1
)
[1] => Array (
[studentID] => 2
[ParentID] => 1
)
)
Array (
[0] => Array (
[studentID] => 5
[ParentID] => 1
)
[1] => Array (
[studentID] => 7
[ParentID] => 3
)
)
echo '<table>';
echo '<tr>';
echo '<th>Student ID</th>';
echo '<th>Parent ID</th>';
echo '</tr>';
for($i = 0; $i < count($array); $i++) {
echo '<tr>';
echo '<td>' . $array[$i]['studentID'] . '</td>';
echo '<td>' . $array[$i]['ParentID'] . '</td>';
echo '</tr>';
}
echo '</table>';
所有类都重复相同的数组格式
我可以在单个数组中更改它,以便可以基于studentID在表中获取它吗?在PHP中
array\u merge可以接受数量可变的参数,因此只需使用一点call\u user\u func\u数组技巧,就可以将$result数组传递给它:
$merge=调用用户函数数组('array\u merge',$result)代码>
这基本上就像您键入:
$merged=array\u merge($result[0]、$result[1]、..$result[n])代码>
现在有了5.6,我们有了。。。运算符将数组解包为参数,以便您可以:
$merged=array\u merge(…$result)代码>
并且有相同的结果我想你应该看看多维数组
我的意思是,我认为您不需要将其更改为单个数组,因为它会弄乱数据。在创建表时,应按如下方式循环数组:
Array (
[0] => Array (
[studentID] => 1
[ParentID] => 1
)
[1] => Array (
[studentID] => 2
[ParentID] => 1
)
)
Array (
[0] => Array (
[studentID] => 5
[ParentID] => 1
)
[1] => Array (
[studentID] => 7
[ParentID] => 3
)
)
echo '<table>';
echo '<tr>';
echo '<th>Student ID</th>';
echo '<th>Parent ID</th>';
echo '</tr>';
for($i = 0; $i < count($array); $i++) {
echo '<tr>';
echo '<td>' . $array[$i]['studentID'] . '</td>';
echo '<td>' . $array[$i]['ParentID'] . '</td>';
echo '</tr>';
}
echo '</table>';
echo';
回声';
回音“学生ID”;
回显“父ID”;
回声';
对于($i=0;$i
我希望这就是你正在努力实现的目标