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

前端 未结 6 1051
太阳男子
太阳男子 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 11:57

    You can use array_walk_recursive() for that coupled with a closure:

    $res = array(); // initialize result
    
    // apply closure to all items in $data
    array_walk_recursive($data, function($item) use (&$res) {
        // flatten the array
        $res[] = $item;
    });
    
    print_r($res); // print one-dimensional array
    

提交回复
热议问题