我有'N'个单维数组(其中N表示由sql命令检索的记录数) 如何使用键作为索引将其转换为多维数组? 起初我想到创建一个单独的键数组,然后将它与那些N数组
组合我的输出
Array ( [0] => PONDICHERRY [1] => 31-Jan-2018 [2] => [3] => distance and height are not proportional. )
Array ( [0] => PONDICHERRY [1] => 03-Feb-2020 [2] => [3] => helloooooooooooooo )
我的预期输出
Array ( [0] => Array ( [0] => PONDICHERRY [1] => 31-Jan-2018 [2] => [3] => distance and height are not proportional. ) [1] =>Array ( [0] => PONDICHERRY [1] => 03-Feb-2020 [2] => [3] => helloooooooooooooo ) )
我很难组合数组,但我如何创建这样的?
谢谢
答案 0 :(得分:1)
您可以在阅读行时将它们组合在一起,而不是创建N个单独的数组,然后再将它们组合在一起。
$results = array();
while($row = $query->fetch_row()){
$results[] = $row;
}
// here you have $results in the expected output format