Home  >  Article  >  Backend Development  >  php对二维数组按指定键值key排序示例代码_PHP

php对二维数组按指定键值key排序示例代码_PHP

WBOY
WBOYOriginal
2016-06-01 11:57:44721browse

复制代码 代码如下:
function array_sort($array, $key){
if(is_array($array)){
$key_array = null;
$new_array = null;
for( $i = 0; $i $key_array[$array[$i][$key]] = $i;
}
ksort($key_array);
$j = 0;
foreach($key_array as $k => $v){
$new_array[$j] = $array[$v];
$j++;
}
unset($key_array);
return $new_array;
}else{
return $array;
}
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn