Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

array conversion in php

how would you convert this array:

Array
(
    [0] => Array
        (
            [Contact] => Array
                (
                    [number] => 0425 234 634
                )

        )

    [1] => Array
        (
            [Contact] => Array
                (
                    [number] => 2939 492 235
                )

        )

)

into this array

Array
(
    [0] => 0425 234 634
    [1] => 2939 492 235
)

?

like image 319
ondrobaco Avatar asked Apr 26 '26 11:04

ondrobaco


1 Answers

See Set::extract() It uses xpath notation to extract node values from paths in arrays.

$numbers = Set::extract('/Contact/number', $numbers);

Achieve all this in 1 line in far more understandable code than other examples suggested here.

like image 53
neilcrookes Avatar answered Apr 29 '26 01:04

neilcrookes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!