PHP array recursive sequencing implementation steps

Source: Internet
Author: User
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 ' =&gt      ; 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.