-
largeQ
您可以通过获取旧变量的大小并使用 for 循环来创建一个新数组试试这个<?php// pre_array is your old array and new_array is arranged one...$i = 0;$size = sizeof($pre_array);$new_array = array();for( $x=0 ; $x<$size ; $x++ ){ $temp_array = array( 'make'=>$pre_array['make'][$x]; 'model'=>$pre_array['model'][$x]; 'vehicleno'=>$pre_array['vehicleno'][$x]; 'reg_state'=>$pre_array['reg_state'][$x]; ); array_push($new_array,$temp_array);}print_r($new_array);?>顺便说一句,这是我的第一个答案......呵呵
-
HUH函数
这可以通过使用从原始数组中提取所有键array_keys(),然后使用从foreach()原始数组中获取每个元素的数据来实现:<?php $data = array( "make" => array("Volvo","VolvoNew"), "model" => array ( "FH16","123" ), "vehicleno" => array ("RS95SMB","RS95SMB" ), "reg_state" => array ( "QLDS","QLDS" ) ); print_r($data); $newArray = array(); $newArrayKeys = array_keys($data); //extract all the keys from the associative array $newArrayLength = count($data["make"]); //get number of makes which is the number of elements in new array for($i=0;$i<$newArrayLength;$i++){ $currElement = array(); // loop through all the keys from the original array and grab the data for the current index foreach($newArrayKeys as $key){ $currElement[$key] = $data[$key][$i]; } $newArray[$i] = $currElement; //push current element to the newArray } print_r($newArray);?>
-
HUX布斯
尝试做这样的事情$array = [ "make" => ['Volvo', 'Volvonew'], "model" => ['FH16','123'], "vehicleno" => ['RS95SMB','RS95SMB'], "reg_state" => ['QLDS', 'QLDS']];$list_1 = [];$list_2 = [];foreach($array as $key => $value){ $list_1[$key] = $value[0]; $list_2[$key] = $value[1];}var_dump($list_1);var_dump($list_2);
-
泛舟湖上清波郎朗
另一种方法是通过简单的foreach()循环来迭代多维数组,并根据您的要求将内部第一个和第二个元素值推送到新数组。$i=0;$return = array();foreach($array as $key=>$value) { $return[$i][$key] = $value[$i]; $return[$i+1][$key] = $value[$i+1];}print_r(($return));工作演示: https://3v4l.org/1CBgn