在 PHP 中将多个一维数组转换为单个多维数组


convert multiple single dimensional array to single multi dimensional array in php

我有"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 )  )
我很难

组合数组,但是我如何像这样创建?

谢谢

与其创建 N 个单独的数组,然后再组合它们,不如在读取行时组合它们。

$results = array();
while($row = $query->fetch_row()){
  $results[] = $row;
}
// here you have $results in the expected output format