PHP quickly raises a value in a two-dimensional array as an array key value, the magical effect of array_column.

Give a chestnut:

//假设今有数组如下
$arr = [
    [
        'id' => '100',
        'name' => 'boy',
        'val' => 'handsome',
    ],
    [
        'id' => '200',
        'name' => 'girl',
        'val' => 'beautiful',
    ],
];
//期望将name提为键值, 操作如下
$re = array_column($arr, null, 'name');
print_r($re); //结果如下

[
    'boy' => [
        'id' => '100',
        'name' => 'boy',
        'val' => 'handsome',
    ],
    'girl' => [
        'id' => '200',
        'name' => 'girl',
        'val' => 'beautiful',
    ],
];


There are other applications of this function, see:  https://www.php.net/manual/zh/function.array-column.php 

Guess you like

Origin blog.csdn.net/weixin_37281289/article/details/106211867