When array_combine is used, if the key name is the same, only one is displayed. how can all be displayed?

Source: Internet
Author: User
When array_combine is used, you can only display one key with the same name. $ Sum = Array & nbsp; (& nbsp; [0] & nbsp ;=& gt; & nbsp; 0 & nbsp; [1] & nbsp ;=& gt; & nbsp; 0 & nbsp; [2] & nbsp; = & gt; & nbsp; 0 & nbsp; [3] When array_combine is used, if you want to display only one key with the same name, how can you display all the key names.
$ Sum = Array ([0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 50 [5] => 15 [6] => 0 [7] => 0 [8] => 15 [9] => 15)
$ City = Array ([0] => Nanchang [1] => Ganzhou [2] => Ji 'an [3] => Jiujiang [4] => Nanchang [5] => jiujiang [6] => Pingxiang [7] => outside the province [8] => Nanchang [9] => Jiujiang)

$ Arra1 = array_combine ($ sum, $ city );
The result is as follows.
Array ([0] => outside the province [50] => Nanchang [15] => Jiujiang)
The system displays only one key with the same name...
Is there any way to display it all ..
Is to display the key name and key value completely.

Display as Array ([0] => Nanchang [0] => Ganzhou [0] => Ji 'an [0] => Jiujiang [50] => Nanchang [15] => Jiujiang [0] => Pingxiang [0] => outside the province [15] => Nanchang [15] => Jiujiang)

Is to change the key value of the first array to the key name of the second array,

Share :? 0? [1]? =>? 0? [2]? =>? 0? [3]? =>? 0? [4]? =>? 50? [5]? =>? 15? [6]? =>? 0? [7]? =>? 0 ?... 'Data-pics = ''>
------ Solution --------------------
Can the key names be repeated?
------ Solution --------------------
$ Arr = array_combine ($ city, $ sum );
Echo 'Array (', PHP_EOL;
Foreach ($ arr as $ k => $ v) echo "\ t [$ v] => $ k", PHP_EOL;
Echo ')', PHP_EOL;

Show complete, pure entertainment ......
------ Solution --------------------
Your array does not exist. the same key value in the same dimension cannot contain more than two.

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.