Anderson Montes De oca Anderson Montes De oca - 4 months ago 10
PHP Question

Sort array PHP (Order array php)

This is my array () ...not much English'm using google translator.
I'm printing this array with print_r (). but what I deceo is sort of form this down

Array
(
[0] => Array
(
[0] => 606125999550609
[1] => Patricia
[2] => Michelle
)

[1] => Array
(
[0] => 724417787635260
[1] => Nasshy
[2] => Green
)

[2] => Array
(
[0] => 1121064174618668
[1] => Luisanna
[2] => Rodriguez
)

[3] => Array
(
[0] => 1057585894278115
[1] => Libane
[2] => Heredia
)

)


Basically what I need is to sort this array as follows......
So I do not know how to sort follows in PHP...

Array
(
[0] => 606125999550609
[1] => 724417787635260
[2] => 1121064174618668
[3] => 1057585894278115

[4] => Patricia
[5] => Nasshy
[6] => Luisanna
[7] => Libane

[8] => Michelle
[9] => Green
[10] => Rodriguez
[11] => Heredia
)

Answer

This isn't so much "sorting", its' more of a manipulation/restructure. Using a loop to regenerate your array would be the option, but if you can modify the data from where it comes from, then that's always recommended.

$new = array();
array_map(function($obj) use(&$new) {
    foreach($obj as $i => $elem) {
        $new[$i][] = $elem;
    }
}, $array);

In the example above, we're using array_map() to apply our function() {... that runs the loop of each element, applying it to our $new array.

All you need to do is pass your $array in as you see above.

Example/Demo