How to add the same key values of the two functions to form a new array

Source: Internet
Author: User
How to add the same key values of the two functions to form a new array. $ T1 = Array & nbsp; (& nbsp; [0] & nbsp ;=& gt; & nbsp; 1320 & nbsp; [1] & nbsp ;=& gt; & nbsp; 990 & nbsp; [2] & nbsp; = & gt; & nbsp; 895 & nbsp; [3] & nbsp; = & gt; & how does nbsp add the same key values of the two functions to form a new array.
$ T1 = Array ([0] => 1320 [1] => 990 [2] => 895 [3] => 790 [4] => 775 [5] => 745 [6] => 740 [7] => 680 [8] => 665 [9] => 535)
$ T2 = Array ([0] => Nanchang [1] => Ganzhou [2] => Ji 'an [3] => Jiujiang [4] => Nanchang [5] => jiujiang [6] => Pingxiang [7] => outside the province [8] => Nanchang [9] => Jiujiang)

$ T1 and $ t2 have the same length and their values correspond to each other,
For example
[0] = & gt; 1320
[0] => Nanchang
The number representing Nanchang is 1320. now I want to add the same values in $ t2.

For example, Nanchang
[0] = & gt; 1320
[0] => Nanchang
---------------------
[4] = & gt; 775
[4] => Nanchang
-----------------
[8] = & gt; 665
[8] => Nanchang
How to add the three numbers.

Form the following array:
$ T3 = Array ([2760] => Nanchang [990] => Ganzhou [895] => Ji 'an [2070] => Jiujiang [740] => Pingxiang [680] => outside the province )?
If you use the array_combine function, consider the case where the same key name is ignored.

Share :? 1320? [1]? =>? 990? [2]? =>? 895? [3]? =>? 790? [4]? =>? 775? [5]? =>? 745? [6]? =>? 7 .. 'data-pics = ''>
------ Solution --------------------
$ T1 = array (0 => 1320, 1 => 990, 2 => 895, 3 => 790, 4 => 775, 5 => 745, 6 => 740, 7 => 680, 8 => 665, 9 => 535 );
$ T2 = array (0 => 'nanchang ', 1 => 'ganzhou', 2 => 'Ji 'an ', 3 => 'jiujiang', 4 => 'nanchang ', 5 => 'jiujiang ', 6 => 'pingxiang', 7 => 'off-provincial ', 8 => 'nanchang', 9 => 'jiujiang ');
 
Foreach ($ t2 as $ I =>$ k) @ $ t3 [$ k] + = $ t1 [$ I];
$ T3 = array_flip ($ t3 );
Print_r ($ t3 );
Array ([2760] => Nanchang [990] => Ganzhou [895] => Ji 'an [2070] => Jiujiang [740] => Pingxiang [680] => outside the province)
------ Solution --------------------
No way. your solution is inherently inadequate!

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.