How to combine the same key value, add the key name value, and then form a new array based on the size of the key name value, please kindly advise

Source: Internet
Author: User
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
)

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.