There are two arrays with the same length. how can we keep them consistent after deduplication. For example, $ t1Array & nbsp; (& nbsp; [0] & nbsp; & gt; & nbsp; nanchang & nbsp; [1] & nbsp; & gt; & nbsp; nanchang & nbsp; [2] & nbsp; & gt; & nbsp; Ganzhou & nbsp; [3] & nbsp; & gt; & nbsp; Jiujiang & nbsp; [4] & nbsp; & gt; Ganzhou & has two arrays with the same length. how can they be consistent after deduplication.
For example
$ T1 = Array ([0] => Nanchang [1] => Nanchang [2] => Ganzhou [3] => Jiujiang [4] => Ganzhou [5] => jiujiang)
$ T2 = Array ([0] => 17:48:33 [1] => 12:48:42 [2] => 17:48:23 [3] => 08:40:03 [4] => 10:28:22 [5] => 11:28:13)
Currently, both $ t1 and $ t2 are of the same length. They also have a corresponding relationship. That is t1 [0] and t2 [0]. T1 [1] and t2 [1]... t1 [I] are associated with t2 [I,
I want to implement non-repeated values in t1. Then, in the correspondence with t2, if there are duplicates, the least time in t2 will be retained.
In addition, the values in the new array t22 are in the ascending order.
The result is,
$ T11 = Array ([0] => Jiujiang [1] => Ganzhou [2] => Nanchang)
$ T22 = Array ([0] => 08:40:03 [1] => 17:48:23 [2] => 12:48:42)
You can also combine t1 and t2 into a two-dimensional array for more convenient implementation. thank you.
------ Solution --------------------
$ T1 = Array (0 => 'nanchang ', 1 => 'nanchang', 2 => 'ganzhou ', 3 => 'jiujiang', 4 => 'ganzhou ', 5 => 'jiujiang ');
$ T2 = Array (0 => '2017-09-23 17:48:33 ', 1 => '2017-09-23 12:48:42 ', 2 => '2014-09-21 17:48:23 ', 3 => '2014-09-12 08:40:03', 4 => '2014-09-23 10:28:22 ', 5 => '2017-09-27 11:28:13 ');
Foreach (array_map (null, $ t1, $ t2) as $ r ){
If (! Isset ($ t [$ r [0]) $ t [$ r [0] = $ r [1];
Else $ t [$ r [0] = min ($ t [$ r [0], $ r [1]);
}
Asort ($ t );
$ T11 = array_keys ($ t );
$ T22 = array_values ($ t );
Print_r ($ t11 );
Print_r ($ t22 );
Array
(
[0] => Jiujiang
[1] => Ganzhou
[2] => Nanchang
)
Array
(
[0] => 08:40:03
[1] => 17:48:23
[2] => 12:48:42
)