我有这个数组$data
:
Array
(
[0] => Array
(
[0] => 1
)
[1] => Array
(
)
[2] => Array
(
)
[3] => Array
(
[0] => test@email.net
)
)
每个数组中始终只有一个元素。那么,我如何将$data
数组转换为此?我也需要空值:
Array
(
[0] => 1
[1] =>
[2] =>
[3] => test@email.net
)
答案 0 :(得分:1)
使用array_map
:
$arr = Array
(
[0] => Array
(
[0] => 1
)
[1] => Array
(
)
[2] => Array
(
)
[3] => Array
(
[0] => test@email.net
)
);
function flaten($n)
{
if (isset($n[0])) {
return $n[0];
} else {
return "";
}
}
$resultArray = array_map(flaten, $arr);