0

I want to get the three keys from a multidimensional array in php

for example:

[
    [0]=>[
        'name'     => 'appetizers',
        'category' => 'category1',
        'price'    => 20,
        'desc'     => 'best in it\'s category',
        'brand'    => 'abc'
    ],
    [1]=>[
        'name'     => 'appetizers',
        'category' => 'category2',
        'price'    => 30,
        'desc'     => 'best in it\'s category',
        'brand'    => 'abc2'
    ]
]

the keys I want are name, price and desc I can do this by using loops but i am just curious whether there is any function like array_column as this provide single column with indexing.

the output i want is somewhat like this:

[
        [0]=>[
            'name'     => 'appetizers',
            'price'    => 20,
            'desc'     => 'best in it\'s category'
        ],
        [1]=>[
            'name'     => 'appetizers',
            'price'    => 30,
            'desc'     => 'best in it\'s category',
        ]
    ]

OR this can also be beneficial

[
        [0]=>[
              'appetizers',
              20,
            'best in it\'s category'
        ],
        [1]=>[
             'appetizers',
            30,
            'best in it\'s category',
        ]
    ]
Arun Sharma
  • 123
  • 1
  • 1
  • 7

0 Answers0