Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-13 10:18:11
Original
1167 people have browsed it

复制代码 代码如下:


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;
}
}

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template