How to combine array of array values into one array?

牧云@^-^@ 提交于 2019-12-01 00:22:20
$result = array();
foreach($array as $item) {
    $result = array_merge($result, $item);
}
hakre

You're looking for array_merge to merge the (sub-) arrays. This can be called via call_user_func_array for an easy interface:

$result = call_user_func_array('array_merge', $array);

See as well:

$new_arr = array();
array_walk_recursive($arr, function($item) use(&$new_arr)
{
    $new_arr[] = $item;
});

Considering your array is :

$z = array(
               '14289' =>
               array('a',
                     'b',
                     'c'
                    ),
               '14290' =>
               array('d',
                     'e',
                     'f'
                    ),
               '14291' =>
               array('g',
                     'h',
                     'i'
                    )
              );

then,

$y =array();// use a blank array to get your result
array_map(function($a) use(&$y){ $y = array_merge( $y,array_values($a)); },$z);

var_dump($y);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!