How to add two arrays 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)
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.
Reply to discussion (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
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
Please write code to someone else.
$ 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 => 'Province out', 8 => 'nanchang ', 9 => 'jiujiang'); $ t22 = array_unique ($ t2); $ t11 = array (); foreach ($ t22 as $ key1 => $ c) {foreach ($ t2 as $ key2 => $ c2) {if ($ c = $ c2) {$ t11 [$ key1] + = $ t1 [$ key2] ;}} print_r ($ t11); print_r ($ t22 );
Array ([0] => 2760 [1] => 990 [2] => 895 [3] => 2070 [6] => 740 [7] => 680)
Array ([0] => Nanchang [1] => Ganzhou [2] => Ji 'an [3] => Jiujiang [6] => Pingxiang [7] => outside the province)
Writing code directly is faster than typing ....
$ 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 => 'Province out', 8 => 'nanchang ', 9 => 'jiujiang'); $ t22 = array_unique ($ t2); $ t11 = array (); foreach ($ t22 as $ key1 => $ c) {foreach ($ t2 as $ key2 => $ c2) {if ($ c = $ c2) {$ t11 [$ key1] + = $ t1 [$ key2] ;}} print_r ($ t11); print_r ($ t22 );
Array ([0] => 2760 [1] => 990 [2] => 895 [3] => 2070 [6] => 740 [7] => 680)
Array ([0] => Nanchang [1] => Ganzhou [2] => Ji 'an [3] => Jiujiang [6] => Pingxiang [7] => outside the province)
Writing code directly is faster than typing ....
Thanks.