How to combine the same key values, and add the value of the key name, and then according to the size of the value of the key name to form a new array, please expert pointing.

Source: Internet
Author: User
Array ([615] = Ganzhou [510] = Nanchang [485] = Jiujiang [375] = Nanchang [+] = Ganzhou [295] = Jiujiang [280] = Jiujiang)
How to combine the same key values, and add the value of the key name, and then according to the size of the value of the key name to form a new array, please expert pointing.


Reply to discussion (solution)

Error_reporting (e_all ^ e_notice); $a = array (615 = ' Ganzhou ', 510 = ' Nanchang ', 485 = ' Jiujiang ', 375 = ' Nanchang ', ' = ' Ganzhou ', 295 = ' Jiujiang ', 280 = ' Jiujiang '); foreach ($a as $v = + $k) {  $b [$k] + = $v;} $b = Array_flip ($b);p rint_r ($b);
Array
(
[965] = Ganzhou
[885] = Nanchang
[1060] = Jiujiang
)

No, I'll give you a clue.
Original Array A
Array_value or Arra_unique extract value as array b
Cycle
The original array array_intersect and B for each of the intersection c[i]
Array_keys C[i] key, by the way sum C[i]
Using c[i] and B to generate an array, you do in the loop to do the correspondence is not difficult, sort the output

Deft on hand, a bit mistaken.

Original Array A
Array_value or Arra_unique extracts the value of a as array b
Cycle
The original array array_intersect and B for each of the intersection c[i]
Array_keys C[i] key, by the way sum D[i]
Using d[i] and B to generate an array, you do in the loop to do the correspondence is not difficult, sort the output

  • 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.