For more information about arrays.

Source: Internet
Author: User
For more information about arrays. I am like the next two-dimensional array, and there can be hundreds of entries without intercepting them.

How can I get the first 10 count values in an array like this.

Array (size = 148) 0 => array (size = 4) 'id' => string '31' (length = 2) 'cjshow' => string 'unknown '(length = 6) 'cjvalues' => string '1' (length = 1) 'Count' => string '64' (length = 2) 1 => array (size = 4) 'id' => string '123' (length = 3) 'cjshow' => string 'area a of Shen tie '(length = 10) 'cjvalues' => string '2' (length = 1) 'Count' => string '5' (length = 1) 2 => array (size = 4) 'id' => string '123' (length = 3) 'cjshow' => string 'area B of Shen tie '(length = 10) 'cjvalues' => string '3' (length = 1) 'Count' => string '3' (length = 1) 3 => array (size = 4) 'id' => string '123' (length = 3) 'cjshow' => string 'shentie C-zone '(length = 10) 'cjvalues' => string '4' (length = 1) 'Count' => string '2' (length = 1) 4 => 5 =>... more


Reply to discussion (solution)

foreach($arr as $v) $r[] = v['count'];array_multisort($r, SORT_DESC, $arr);$res = array_slice($arr, 0, 10);

$ Arr = [['id' => '31', 'cjshow' => 'Unknown ', 'cjvalues' => '1 ', 'Count' => '64',], ['id' => '000000', 'cjshow '=> 'shentie a region', 'cjvalues' => '2 ', 'Count' => '5',], ['id' => '000000', 'cjshow '=> 'area B of shentie ', 'cjvalues' => '3', 'count' => '3',], ['id' => '123 ', 'cjshow' => 'shentie C region', 'cjvalues' => '4', 'count' => '2',], ['id' => '000000', 'cjshow '=> 'shentie C region', 'cjvalues' => '4 ', 'Count' => '1',], ['id' => '000000', 'cjshow '=> 'area C of shentie ', 'cjvalues' => '4', 'count' => '10',], ['id' => '123 ', 'cjshow' => 'shentie C region', 'cjvalues' => '4', 'count' => '11',], ['id' => '000000', 'cjshow '=> 'shentie C region', 'cjvalues' => '4 ', 'Count' => '12',], ['id' => '000000', 'cjshow '=> 'area C of shentie ', 'cjvalues' => '4', 'count' => '23',], ['id' => '123 ', 'cjshow' => 'shentie C region', 'cjvalues' => '4', 'count' => '24',], ['id' => '000000', 'cjshow '=> 'shentie C region', 'cjvalues' => '4 ', 'Count' => '25',], ['id' => '000000', 'cjshow '=> 'area C of shentie ', 'cjvalues' => '4', 'count' => '26',], ['id' => '123 ', 'cjshow' => 'shentie C region', 'cjvalues' => '4', 'count' => '27',], ['id' => '000000', 'cjshow '=> 'shentie C region', 'cjvalues' => '4 ', 'Count' => '28',],]; $ count = array_column ($ arr, 'count'); array_multisort ($ count, SORT_DESC, $ arr ); $ B = array_slice ($ arr, 0, 10); var_dump ($ B );


Array_multisort is used to sort arrays. if the php version cannot use the array_column function, you can only use the foreach Group $ count array.

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.