我有这个多维
PHP数组(如下).
Array
(
[0] => Array
(
[2] => one@example.com
)
[1] => Array
(
[4] => two@example.com
)
[2] => Array
(
[3908] => twenty@example.com
)
[3] => Array
(
[2548] => eleven@example.com
)
[4] => Array
(
[3099] => ten@example.com
)
[5] => Array
(
[5283] => six@example.com
)
)
我想知道我怎么能合并?还是结合?或者简单地使用PHP(下面)这样做.
Array
(
[2] => one@example.com
[4] => two@example.com
[3908] => twenty@example.com
[2548] => eleven@example.com
[3099] => ten@example.com
[5283] => six@example.com
)
救命
最佳答案 您可以通过
call_user_func_array()将第二级元素“提升”到第一级元素.虽然array_merge()重新索引数组,但
array_replace()不会保留原始键,这使得它成为单行:
$a = call_user_func_array('array_replace', $a);
测试:
<?php
$a = array (
array (2 => 'one@example.com'),
array (4 => 'two@example.com'),
array (3908 => 'twenty@example.com'),
array (2548 => 'eleven@example.com'),
array (3099 => 'ten@example.com'),
array (5283 => 'six@example.com'),
);
$a = call_user_func_array('array_replace', $a);
var_dump($a);