Search code examples
phparray-merge

PHP array merge, remove [u]


I have an array given below...

Array
(
[0] => Array
    (
        [u] => Array
            (
                [id] => 396
                [first_name] => Gyan
                [last_name] => sharma
                [email] => [email protected]
                [phone_number] => 
            )

    )

[1] => Array
    (
        [u] => Array
            (
                [id] => 589
                [first_name] =>  deep
                [last_name] => sharma
                [email] => [email protected]
                [phone_number] => 
            )

    )
)

I just want to remove the [u] from each array, Like array given below.

Array
(
[0] => Array
    (
         [id] => 396
         [first_name] => Gyan
         [last_name] => sharma
         [email] => [email protected]
         [phone_number] => 


    )

[1] => Array
    (
         [id] => 589
         [first_name] =>  deep
         [last_name] => sharma
         [email] => [email protected]
         [phone_number] => 

    )
)

I can do this by foreach() loop, but it is lengthy process..

Can anyone tell me the shortest way for this.

Help me.

Thanks in Advance.


Solution

  • You have to use array_column() like below:-

    $array = array_column($array,'u');
    

    Output:- https://eval.in/833258