Two-dimensional arrays are sorted by one of the key values.

Source: Internet
Author: User
Two-dimensional arrays are sorted by one of the key values :? Phpfunctionmultisort (} Getargsnumber. $ arg_countfunc_num_args (); arrays. for ($ i1; $ I $ arg_count; $ I ++) {$ argfunc_get_arg ($ I); if (! Preg_match (

Two-dimensional arrays are sorted by one of the key values :? Php function multisort (} // Get args number. $ arg_count = func_num_args (); // Get keys to sort by and put them to SortRule array. for ($ I = 1; $ I $ arg_count; $ I ++) {$ arg = func_get_arg ($ I); if (! Preg_match (

Two-dimensional arrays are sorted by one of the key values:

 $ Info) {foreach ($ key_name_list as $ key_name) {$ {$ key_name} [$ key] = $ info [$ key_name] ;}} // Create the eval string and eval it. $ eval_str = 'array _ multisort ('. implode (',', $ sort_rule ). ', $ array);'; eval ($ eval_str); return $ array ;} $ data = Array (0 => Array ('title' => 'u8-HR Ningxia ', 'linkline' => 'space. php? Uid = 4018 & do = album & id = 498 ', 'time' => 1275012236, 'content' => 'u8-HR Ningxia ', 'from' => 'alipay'), 1 => Array ('title' => 'u8 AII-in-One national tour-Jining station ', 'linkline' => 'space. php? Uid = 2770 & do = album & id = 339 ', 'time' => 1268628887, 'content' => 'u8 AII-in-One national tour-Jining station ', 'from' => 'alipay'), 2 => Array ('title' => 'u8 ALL-IN-ONE tour-Henan station ', 'linkline' => 'space. php? Uid = 1282 & do = album & id = 359 ', 'time' => 1269333609, 'content' => 'u8 ALL-IN-ONE tour-Henan station ', 'from' => 'alipay'), 3 => Array ('title' => 'First click to U8 All-in-One experience disc', 'linkline' => 'space. php? Uid = 3857 & do = album & id = 665 ', 'time' => 1285049939, 'content' => 'upload to U8 All-in-One experience disks ', 'from' => 'alipay'); print_r (multisort ($ data, 'time', 'sort _ desc');?>

In this way, the $ data array is reordered by its own time key.

Original article address: Two-dimensional arrays are sorted by one of the key values. Thank you for sharing it with the original author.

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.