How to convert two dimensional array to one dimensional array in php?

前端 未结 6 1037
太阳男子
太阳男子 2021-02-01 11:17

I am Having an mutidimensional array getting result like given below

Array
(
    [0] => Array
        (
            [0] => 70
        )

    [1] => Arra         


        
6条回答
  •  遥遥无期
    2021-02-01 12:09

    This should do the trick

    $final = array();
    foreach ($outer as $inner) {
      $final = array_merge($final, $inner);
    }
    var_dump($final);
    

    Or you could use array_reduce() if you have PHP >= 5.3

    $final = array_reduce($outer, function($_, $inner){
      return $_ = array_merge((array)$_, $inner);
    });
    var_dump($final);
    

提交回复
热议问题