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