子沫
php把一个二维数组中的某个或者某些字段当成 key
04/19
本文最后更新于2020年04月01日,已超过1788天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!
/**
* 把一个二维数组中的某个或者某些字段当成 key
*
* @param array $array 二维数组
* @param string|array $field 字段,liuchao 修改
*
* @return array
*/
function useFieldAsArrayKey($array, $field) {
$newArr = [];
if (is_array($field)) {
foreach ($array as $key => $value) {
$newKey = '';
foreach ($field as $f) {
$newKey .= $value[strval($f)];
}
if (!isset($newArr[$newKey])) {
$newArr[$newKey] = $value;
}
}
} else {
foreach ($array as $key => $value) {
$newArr[$value[strval($field)]] = $value;
}
}
return $newArr;
}


版权属于:
Strjson博客-专注于各种精品源码、精品软件、技术教程分享、黑客技术、破解教程(爱你在心口难开、没事写一写)
本文链接:
https://jpgke.com/jiaocheng/110.html(转载时请注明本文出处及文章链接)
作品采用: