There are two arrays, the same length, after the weight, how can still be consistent

Source: Internet
Author: User
There are two arrays, the same length, and how to remain consistent after the weight is gone.
Like what
$t 1=array ([0] = = Nanchang [1] = Nanchang [2] = Ganzhou [3] = Jiujiang [4] = Ganzhou [5] = Jiujiang)
$t 2=array ([0] = 2013-09-23 17:48:33 [1] = 2013-09-23 12:48:42 [2] = 2013-09-21 17:48:23 [3] = 2013-09-12 08:40:03 [4] = 2013-09-23 10:28:22 [5] = 2013-09-27 11:28:13)

Now $T1 and $t2 are all the same length. And they also have a correspondence relationship. That's t1[0] and t2[0]. T1[1] and T2[1].....t1[i] and T2[i] are connected,

I now want to realize that the value within the T1 is not duplicated. Then, in correspondence with the T2, if there are duplicates, keep the T2 inside the smallest time.
And the value inside the new array t22 is the order from small to large.
Got the result I think is that
$t 11=array ([0] = Jiujiang [1] = Ganzhou [2] = Nanchang)
$t 22=array ([0] = 2013-09-12 08:40:03 [1] = 2013-09-21 17:48:23 [2] = 2013-09-23 12:48:42)

or merging T1,t2 into a two-dimensional array is more convenient to implement, thank you.

------Solution--------------------

$t 2 = Array (0 = ' 2013-09-23 17:48:33 ', 1 = ' 2013-09-23 12:48:42 ', 2 = ' 2013-09-21 17:48:23 ', 3 = ' 2013-0 9-12 08:40:03 ', 4 = ' 2013-09-23 10:28:22 ', 5 = ' 2013-09-27 11:28:13 ');

foreach (Array_map (null, $t 1, $t 2) as $r) {
if (! isset ($t [$r [0]]) $t [$r [0]] = $r [1];
else $t [$r [0]] = min ($t [$r [0]], $r [1]);
}
Asort ($t);
$t one = Array_keys ($t);
$t = Array_values ($t);
Print_r ($t 11);
Print_r ($t 22);
Array
(
[0] = Jiujiang
[1] = Ganzhou
[2] = Nanchang
)
Array
(
[0] = 2013-09-12 08:40:03
[1] = 2013-09-21 17:48:23
[2] = 2013-09-23 12:48:42
)
  • 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.