This article mainly introduces the code for sorting multi-dimensional arrays by specified values in php, which can achieve sorting effects similar to database sorting fields. For more information, see
This article mainly introduces the code for sorting multi-dimensional arrays by specified values in php, which can achieve sorting effects similar to database sorting fields. For more information, see
The business needs to be sorted by an element in a multi-dimensional array, which is also very easy to implement in PHP. A function can call a callback function. Paste the Code:
The Code is as follows:
$ Arr = array (
'Index' => array ('name' => 'homepage ', 'order' => 3 ),
'Intro' => array ('name' => 'enterprise profile ', 'order' => 2 ),
'News' => array ('name' => 'news list', 'order' => 1 ),
'Product' => array ('name' => 'product Center', 'order' => 4 ),
'Message' => array ('name' => 'guest 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'];
}
$ Arr is sorted by order size ......