PHP中是否有任何功能可以从多维错误中获取特定键

时间:2018-09-20 12:07:41

标签: php

我想从php中的多维数组中获取三个键

例如:

[
    [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'
    ]
]

我想要的键是namepricedesc 我可以使用循环来做到这一点,但是我很好奇是否有像array_column这样的函数,因为它为索引提供了单列。

我想要的输出有点像这样:

[
        [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',
        ]
    ]

0 个答案:

没有答案