How do two arrays form a new array based on the same addition?

Source: Internet
Author: User
How to add two arrays 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; & nbsp; 790 & nbs: How do two arrays form a new array based on the same addition?
$ 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)

You can create a $ t11 = record value,
$ T22 = This is the recorded region.
This ensures that the data is overwritten without duplicate names, but you do not know whether the calculation can be done in this way.

$ T11 = Array ([0] => 2760 [1] => 990 [2] => 895 [3] => 2070 [4] => 740 [5] => 680)
$ T22 = Array ([0] => Nanchang [1] => Ganzhou [2] => Ji 'an [3] => Jiujiang [4] => Pingxiang [5] => outside the province)

The calculated result is shown above .. Remove the same t2, and add the key names in t1. Share :? 1320? [1]? =>? 990? [2]? =>? 895? [3]? =>? 790? [4]? =>? 775? [5]? =>? 745? [6]? =>? 7 .. 'data-pics = ''>
------ Solution --------------------
Creating an array first is the result of removing duplicates from the $ t2 array (t22)

Loop this new array (t22), for each place name, go to the loop $ t2 array. if the two values are the same, take the key corresponding to $ t2 to $ t1 and add it to a new array ($ t11) (The current loop of the new array), and continue until every $ t2 sub-element in the current cycle of t22 is compared.
Continue to complete the $ t22 loop

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.