Please give us some advice on how to combine the same key values, add the key name values, and then form a new array based on the size of the key name values. Array & nbsp; (& nbsp; [615] & nbsp ;=& gt; & nbsp; Ganzhou & nbsp; [510] & nbsp ;=& gt; & nbsp; nanchang & nbsp; [485] & nbsp ;=& gt; & nbsp; Jiujiang & how to combine the same key value and add the key name values, then a new array is formed based on the size of the key name value.
Array ([615] => Ganzhou [510] => Nanchang [485] => Jiujiang [375] => Nanchang [350] => Ganzhou [295] => Jiujiang [280] => Jiujiang)
Please give us some advice on how to combine the same key values, add the key name values, and then form a new array based on the size of the key name values. Share :? Ganzhou? [510]? =>? Nanchang? [485]? =>? Jiujiang? [375]? =>? Nanchang? [350]? =>? Ganzhou? [295]? =>? Jiujiang? [280]? =... 'Data-pics = ''>
------ Solution --------------------
Error_reporting (E_ALL ^ E_NOTICE );
$ A = array (615 => 'ganzhou ', 510 => 'nanchang', 485 => 'jiujiang ', 375 => 'nanchang', 350 => 'ganzhou ', 295 => 'jiujiang ', 280 => 'jiujiang ');
Foreach ($ a as $ v => $ k ){
$ B [$ k] + = $ v;
}
$ B = array_flip ($ B );
Print_r ($ B );
Array
(
[1, 965] => Ganzhou
[1, 885] => Nanchang
[1, 1060] => Jiujiang
)