Convert multidimensional array into single array

后端 未结 20 1563
时光取名叫无心
时光取名叫无心 2020-11-22 10:39

I have an array which is multidimensional for no reason

/* This is how my array is currently */
Array
(
[0] => Array
    (
        [0] => Array
                


        
相关标签:
20条回答
  • 2020-11-22 11:27

    Try this it works for me:

        $newArray = array();
                foreach($operator_call_logs as $array) {
                    foreach($array as $k=>$v) {
                        $newArray[$k] = $v;
                    }
                }
    
    0 讨论(0)
  • 2020-11-22 11:29

    Multi dimensional array to single array with one line code !!! Enjoy the code.

    $array=[1=>[2,5=>[4,2],[7,8=>[3,6]],5],4];
    $arr=[];
    array_walk_recursive($array, function($k){global $arr; $arr[]=$k;});
    print_r($arr);
    

    ...Enjoy the code.

    0 讨论(0)
提交回复
热议问题