我当前的循环格式是这样的:
https://github.com/jaswinder97/active_merchant
和所有类的数组重复格式相同
我可以在单个数组中更改它,以便可以基于studentID在表中提取它吗?
答案 0 :(得分:0)
在PHP中
array_merge可以使用可变数量的参数,因此使用一些call_user_func_array技巧可以将$ result数组传递给它:
$merged = call_user_func_array('array_merge', $result);
这基本上就像你输入的那样:
$merged = array_merge($result[0], $result[1], .... $result[n]);
现在有了5.6,我们有...运算符将数组解包到参数中,所以你可以:
$merged = array_merge(...$result);
并得到相同的结果
答案 1 :(得分:0)
我认为你应该看看多维数组。
http://www.w3schools.com/php/php_arrays_multi.asp
我的意思是我认为您不需要将其更改为单个阵列,因为它会弄乱数据。当你正在制作表时,你应该像这样遍历数组:
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>';
我希望这是你想要完成的事情。