Home  >  Article  >  Backend Development  >  PHP sort two-dimensional array by specified key value sample code_PHP tutorial

PHP sort two-dimensional array by specified key value sample code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:17:47821browse

复制代码 代码如下:

function array_sort($array, $key){
if(is_array($array)){
$key_array = null;
$new_array = null;
for( $i = 0; $i < count( $array ); $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;
}
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/621721.htmlTechArticle复制代码 代码如下: function array_sort($array, $key){ if(is_array($array)){ $key_array = null; $new_array = null; for( $i = 0; $i count( $array ); $i++ ){ $key_array[$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