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

在php中将多个一维数组转换为单个多维数组,php,html,arrays,multidimensional-array,Php,Html,Arrays,Multidimensional Array,我有“N”个一维数组(其中N表示sql命令检索到的记录数) 如何将其转换为以键为索引的多维数组? 起初,我想创建一个单独的密钥数组,然后将其与这些N个数组组合 我的输出 Array ( [0] => PONDICHERRY [1] => 31-Jan-2018 [2] => [3] => distance and height are not proportional. ) Array ( [0] => PONDICHERRY [1] => 03

我有“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

两个独立的数组使用$arr[]=array\u merge除了索引是字符串而不是整数外,您的输出会为我提供如下内容:数组([0]=>array([StationName]=>PONDICHERRY[DOI]=>2018年1月31日[备注]=>距离和高度不成比例。烧瓶a[雨量计]=>)[1]=>array([StationName]=>PONDICHERRY[DOI]=>2020年2月3日[备注]=>Helloooooo[雨量计]=>)