1

I have a multidimensional array,

Array 
 (
    [0] => Array
        (
            [ID] => 53
            [Lft] => 11
            [Rght] => 24
            [Title] => cafeteria
            [Description] => Cafeteria
        )

    [1] => Array
        (
            [ID] => 55
            [Lft] => 20
            [Rght] => 21
            [Title] => sanitary
            [Description] => Sanitary
        )

    [2] => Array
        (
            [ID] => 58
            [Lft] => 22
            [Rght] => 23
            [Title] => medic
            [Description] => Medic
        )

 )

How do I get an array of all the ids easily, without having to loop through each the traditional way?

Mohd Abdul Mujib
  • 13,071
  • 8
  • 64
  • 88

1 Answers1

3

We can use array_column to extract a single dimensional array from the multidimensional array based on a key.

$roles = array_column($roles, 'ID');

Returns

Array (
    [0] => 53
    [1] => 55
    [2] => 58
)
Mohd Abdul Mujib
  • 13,071
  • 8
  • 64
  • 88