二维数组排序
function array_sort($arr, $keys, $order = 0) {
if (!is_array($arr)) {
return false;
}
$keysvalue = array();
foreach ($arr as $key => $val) {
$keysvalue[$key] = $val[$keys];
}
if ($order == 0) {
asort($keysvalue);
} else {
arsort($keysvalue);
}
reset($keysvalue);
foreach ($keysvalue as $key => $vals) {
$keysort[$key] = $key;
}
$new_array = array();
foreach ($keysort as $key => $val) {
$new_array[$key] = $arr[$val];
}
return $new_array;
}
二维数组去重
function unique_2d_array_by_key($_2d_array, $unique_key) {
$tmp_key[] = array();
foreach ($_2d_array as $key => &$item) {
if (is_array($item) && isset($item[$unique_key])) {
if (in_array($item[$unique_key], $tmp_key)) {
unset($_2d_array[$key]);
} else {
$tmp_key[] = $item[$unique_key];
}
}
}
return $_2d_array;
}
标签:unique,数组,keysvalue,2d,item,二维,key,array,PHP
From: https://www.cnblogs.com/sunr/p/17255274.html