我的代码:
Array (
[0] => Array ( [15-3] => 1 )
[1] => Array ( [16-3] => 2 )
[2] => Array ( [15-4] => 3 )
[3] => Array ( [16-4] => 4 )
[4] => Array ( [15-3] => 11 )
[5] => Array ( [16-3] => 22 )
[6] => Array ( [15-4] => 33 )
[7] => Array ( [16-4] => 44 )
[8] => Array ( [15-3] => 111 )
[9] => Array ( [16-3] => 222 )
[10] => Array ( [15-4] => 333 )
[11] => Array ( [16-4] => 444 )
[12] => Array ( [15-3] => 1111 )
[13] => Array ( [16-3] => 2222 )
[14] => Array ( [15-4] => 3333 )
[15] => Array ( [16-4] => 4444 )
)
在上面我的数据放在一个数组中的数组中,如何将所有值合并为一个像单个数组
答案 0 :(得分:0)
你的问题中存在一些混乱。我知道你需要这样。
Array (
[15-3] => 1
[16-3] => 2
[15-4] => 3
........
)
然后在PHP中使用array_values()
函数
$inner_array = array_values($initial_array);
答案 1 :(得分:0)
我还添加了上一个问题的完整代码,但我将密钥更改为值:
$attri_ids_all=Array ("0" => "15-3" ,"1" => "16-3", "2" => "15-4" ,"3" => "16-4" ,"4" => "15-3" ,"5" => "16-3", "6" => "15-4" ,"7" => "16-4", "8" => "15-3", "9" => "16-3", "10" => "15-4", "11" => "16-4", "12" => "15-3", "13" => "16-3", "14" => "15-4", "15" => "16-4" );
$inventory_code_qty=Array ("0" => "1", "1" => "2", "2" => "3", "3" => "4" ,"4" => "11" ,"5" => "22" ,"6" => "33", "7" => "44", "8" => "111" ,"9" => "222" ,"10" => "333", "11" => "444" ,"12" => "1111", "13" => "2222", "14" => "3333", "15" => "4444" );
function foo($key, $val) {
return $val;
}
$arrResult = array_map('foo', $attri_ids_all, $inventory_code_qty);
$arr1=array_values($attri_ids_all);
$arr2 = $arrResult;
echo "<pre>";
print_r(array_combine($arr2,$arr1));
echo "</pre>";