This time for everyone to bring the PHP array recursive ordering implementation steps in detail, the PHP array recursive sorting implementation of the considerations are what, the following is the actual case, take a look.
/** * Recursion is sorted by a specific key array * @param $data * @param string $orderKey * @param string $sonKey * @param int $orderBy * @return Mixe D */function Recursion_orderby ($data, $orderKey = ' order ', $sonKey = ' children ', $orderBy = sort_asc) {$func = function ( $value) Use ($sonKey, $orderKey, $orderBy) {if (Isset ($value [$sonKey]) && is_array ($value [$sonKey])) {$v alue[$sonKey] = Recursion_orderby ($value [$sonKey], $orderKey, $sonKey, $orderBy); } return $value; }; Return Array_orderby (Array_map ($func, $data), $orderKey, $orderBy);} $a = [[' Order ' = 0,], [' Order ' =-1, ' children ' = = [' Order ' = 0,], [' Order ' =-2, ' children ' = = [' Order ' = 0], [' Order ' =-1], [ ' Order ' = 1],],],], [' order ' = = 2,],];var_dump (Recursion_orderby ($a));/** * Output: Array (3 {[0] = = Array (2) {' order ' = = Int ( -1) ' Children ' = + Array (2) {[0] = = Array (2) {' order ' = = Int ( -2) ' Children ' = + Array (3) {[0] = = Array (1) {' Order ' => ; int ( -1)} [1] = = Array (1) {' order ' = = Int (0)} [2] = = Array (1) {' Order ' = = Int (1)}}} [1] = = Array (1) {' order ' = = Int (0)}}} [1] = + Array (1) {' Order ' = = Int (0)} [2] = = Array (1) {' order ' = = Int (2)}}*/
Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!
Recommended reading:
thinkphp Framework PDO Connection database steps
PHP7.1 Internal Installation Yaf extension steps detailed