How does the PHP array_multisort () function keep the number keys from being re-indexed

Source: Internet
Author: User
php
$arr = array('100'=>array('age'=>22,'name'=>'jack','date'=>'2014'),'110'=>array('age'=>23,'name'=>'mary','date'=>'2012'),'120'=>array('age'=>24,'name'=>'lilei','date'=>'2015'));array_multisort对数组按age倒序后date倒序,然后120被重新索引为0,怎么保持呢?目前是用$arr_another = $arr保留原数组//感谢公子uasort($arr, function($a, $b) { if( $a['age'] === $b['age'] ){ return $a['date'] - $b['date']; } return $a['age'] - $b['age'];});print_r($arr);

Reply content:

php
$arr = array('100'=>array('age'=>22,'name'=>'jack','date'=>'2014'),'110'=>array('age'=>23,'name'=>'mary','date'=>'2012'),'120'=>array('age'=>24,'name'=>'lilei','date'=>'2015'));array_multisort对数组按age倒序后date倒序,然后120被重新索引为0,怎么保持呢?目前是用$arr_another = $arr保留原数组//感谢公子uasort($arr, function($a, $b) { if( $a['age'] === $b['age'] ){ return $a['date'] - $b['date']; } return $a['age'] - $b['age'];});print_r($arr);

The new additions are not very understanding, if you want to follow age, date the priority of the sort, just write it right: Http://3v4l.org/MRYrt
Would it be nice to do it two times if we were to sort the date first and then do uasort it again? Code See: Http://3v4l.org/8FstY

  • Related Article

    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.