Is it possible to assign keys to array elements in PHP from a value column with less code?

前端 未结 3 1122
日久生厌
日久生厌 2021-01-20 00:16

Let\'s assume I have an array of elements, which are arrays themselves, like so:

$array = [
    [\'foo\' => \'ABC\', \'bar\' => \'DEF\'],
    [\'foo\'          


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-20 00:28

    Notice array-column can get index as well (third argument):

    mixed $index_key = NULL

    So just use as:

    array_column($array, null, 'foo');
    

提交回复
热议问题