php Multidimensional Array by Specified value Sort Implementation Code
- 2021-07-13 04:31:39
- OfStack
Ha ha, the business needs to be sorted by a certain element in the multidimensional array, which is also very easy to realize in PHP. One function calls one callback function. Post code:
$arr = array(
'index'=>array( 'name'=>' Home page ','order'=>3),
'intro'=>array( 'name'=>' Enterprise profile ','order'=>2),
'news'=>array( 'name'=>' News developments ','order'=>1 ),
'product'=>array( 'name'=>' Product center ','order'=>4 ),
'message'=>array( 'name'=>' Visitor message ','order'=>7 ),
'position'=>array( 'name'=>' Talent recruitment ','order'=>6),
'contact'=>array( 'name'=>' Contact us ','order'=> 5 )
);
uasort($arr, 'cmp');
public function cmp($a, $b){
return $a['order'] - $b['order'];
}
At this time, $arr is sorted by order size, hehe...