Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am Having an mutidimensional array getting result like given below

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

    [1] => Array
        (
            [0] => 67
        )

    [2] => Array
        (
            [0] => 75
            [1] => 73
            [2] => 68
        )

    [3] => Array
        (
            [0] => 68
        )

    [4] => Array
        (
            [0] => 76
        )

)

But I need to convert it to single array

And I want to convert in to single dimensional array as

Array
(
[0] => 70
[1] => 67
[2] => 75
[3] => 73
[4] => 68
[5] => 68
[6] => 76
)

How to convert it using php functions?

Or Is there any other way to do it?

like image 479
Durgesh Sonawane Avatar asked Dec 01 '22 20:12

Durgesh Sonawane


1 Answers

You can try

$it =  new RecursiveIteratorIterator(new RecursiveArrayIterator($data));
$l = iterator_to_array($it, false);

var_dump($l); // one Dimensional 
like image 192
Baba Avatar answered Dec 19 '22 04:12

Baba