//示例三维数组 $bom = Array ( [0] => Array ( [0] => Array ( [carrier] => 2 ) [1] => Array ( [name] => B1(硝酸) ) [2] => Array ( [material_id] => 6 ) [3] => Array ( [content] => 1 ) [4] => Array ( [content_unit] => g ) [5] => Array ( [dosage] => 1.087 ) [6] => Array ( [dosage_unit] => kg ) ) [1] => Array ( [0] => Array ( [carrier] => 2 ) [1] => Array ( [name] => K3(MNB)43% ) [2] => Array ( [material_id] => 8 ) [3] => Array ( [content] => 2 ) [4] => Array ( [content_unit] => g ) [5] => Array ( [dosage] => 4.651 ) [6] => Array ( [dosage_unit] => kg ) ) )
//转为二维数组 function array3_to_array2($bom) { $b = array(); foreach ($data as $v) { $c = array(); foreach ($v as $vv) { $key = array_keys($vv); //获取数组的键 $value = array_values($vv); //获取数组的值 $c[$key[0]] = $value[0]; //拼接 } $b[] = $c; } return $b; }
//返回的二维数组 Array ( [0] => Array ( [carrier] => 2 [name] => B1(硝酸) [material_id] => 6 [content] => 1 [content_unit] => g [dosage] => 1.087 [dosage_unit] => kg ) [1] => Array ( [carrier] => 2 [name] => K3(MNB)43% [material_id] => 8 [content] => 2 [content_unit] => g [dosage] => 4.651 [dosage_unit] => kg ) )