【转】php 多维数组指定某个值作为键

臭大佬 2021-05-24 11:51:59 2150
php 
简介 php 多维数组指定某个值作为键

代码

二维数组,把键为’id’的值作为新数组(new_arr)的键,值为原来的值。

$temp_key = array_column($arr,'id');  //键值
$new_arr = array_combine($temp_key,$arr) ;

来源 :https://blog.csdn.net/a1005398026/article/details/96443305