<?php /* * 遍历数组中某个字段的值 作为 键 返回新数组 */ function arrayChangeKeyByField($list, $searchKey) { $arr = []; if (!$searchKey) { return $list; } foreach ($list as $k => $v) { if (isset($v[$searchKey])) { $arr[$v[$searchKey]] = $v; } } return $arr ? $arr : $list; }