This article introduces, PHP two-dimensional array sorting two examples, are relatively simple, are learning php array sorting friends, can make a reference, is also good. Share a piece of code that implements the ordering of two-dimensional arrays in PHP. Code:
'; Print_r ($good); Echo ' '; $hot =array (); $follow =array (); foreach ($good as $k = $v) {$hot [$k] = $v [' hot ']; $follow [$k] = $v [' Follow '];}//two-D array sorting Method One, first press the hot field descending, then press follow descending array_multisort ($hot, Sort_desc, $follow, Sort_desc, $good); Echo '';p rint_r ($good); Echo ' ';//Method two function xx ($a, $b) {if ($a [' price '] = = $b [' price ']) {return ($a [' hot '] < $b [' hot '])? 1:-1;;} return ($a [' Price '] < $b [' price ']? 1:-1;} $a = Array (0=>array (' Price ' =>123, ' hot ' =>34543), 1=>array (' Price ' =>434, ' hot ' =>234), 2=>array (' Price ' =>42, ' hot ' =>2232), 3=>array (' Price ' =>42, ' hot ' =>235432), 4=>array (' Price ' =>33443, ' hot ' =>12), 4=>array (' Price ' =>434, ' hot ' =>1211), Usort ($a, ' xx '); Echo '';p rint_r ($a); Echo ' ';>>> For more information, check out the PHP array sorting method Daquan <<< |