Share a PHP function to find the intersection of 5 Arrays _php Tutorial

Source: Internet
Author: User
/** the number of collisions to find the overlapping values of multiple numbers returned: The following Array of the reorganization, as follows: $arr =array (0=> ",///5 parts of the overlap 1=> ',//The 1th group removed the value of [0] after 2=> ',//2nd number removed [0 ] After the value of 3=> ',//3rd number of [0] after the value of 4=> ',///4th number of [0] after the value of the 5=> ',//5th number of the [0] after the value of the []; parameters: 5 numbers to be restructured/**/public Static Function Jiaoji ($arr 1, $arr 2, $arr 3, $arr 4, $arr 5) {IF (! Is_array ($arr 1) Or! Is_array ($arr 2) Or! Is_array ($arr 3) Or! Is_array ($arr 4) Or! Is_array ($arr 5)) {Throw New Exception (' Error: '. __line__. ', Parameters wrong! ');D IE ();} $arr =array ();//Find the repeating part of these 5 numbers, and give the $arr[0]{//to the combined number of $narr=array_merge ($arr 1, $arr 2, $arr 3, $arr 4, $arr 5);//derating foreach ($ Narr as $v) {$v = Implode ("', $v);//descending dimension $temp[] = $v;} UnSet ($narr);//To repeat $unique_arr = Array_unique ($temp);//differential Set $repeat_arr = Array_diff_assoc ($temp, $unique _arr); UnSet ($ Temp, $unique _arr),//Go to duplicate $repeat_arr=array_unique ($repeat _arr),//($repeat _arr as $k + $v) {$v = Explode (' ', $v); $v [' gid ']= $v [0];unset ($v [0]), $v [' Cod ']= $v [1];unset ($v [1]); $v [' Tid1 ']= $v [2];unset ($v [2]); $v [' Tid2 ']= $v [3] ; UnSet ($v [3]); $v [' Stime ']= $v [4];unset ($v [4]); $temp [] = $v;} $arr [0]= $temp; UnSet ($tEMP, $repeat _arr);} /** Remove the partial array (5) {["GID"]=>string (1) "2" ["Cod"]=>string (4) "4002" ["Tid1"]=>string (3) "184" that contain $arr[0] in 5 numbers [ "Tid2"]=>string (3) "199" ["Stime"]=>string (+) "2013-07-25 02:19:00"}/**/$max =max (count ($arr 1), COUNT ($arr 2), Count ($arr 3), COUNT ($arr 4), COUNT ($arr 5)); Foreach ($arr [0] as $k + $v) {for ($i =0; $i < $max; $i + +) {//Remove arr1 and $arr[0] repeat if (IsSet ($arr 1[$i])) {if ($arr 1[$i] GID ']== $v [' gid '] and $arr 1[$i] [' Cod ']== $v [' cod '] and $arr 1[$i] [' tid1 ']== $v [' Tid1 '] and $arr 1[$i] [' Tid2 ']== $v [' Tid2 '] and $arr 1[$i] [' stime ']== $v [' stime ']) {unSet ($arr 1[$i]);}} Remove arr2 and $arr[0] (IsSet ($arr 2[$i)) {if ($arr 2[$i [' gid ']== $v [' gid '] and $arr 2[$i] [' Cod ']== $v [' cod '] and $arr 2 [$i] [' Tid1 ']== $v [' Tid1 '] and $arr 2[$i] [' Tid2 ']== $v [' Tid2 '] and $arr 2[$i] [' stime ']== $v [' stime ']) {unSet ($arr 2[$i]);}} Remove Arr3 and $arr[0] (IsSet ($arr 3[$i)) {if ($arr 3[$i [' gid ']== $v [' gid '] and $arr 3[$i] [' Cod ']== $v [' cod '] and $arr 3 [$i] [' Tid1 ']== $v [' Tid1 '] and $arr 3[$i] [' Tid2 ']== $v [' Tid2 '] and $arr 3[$i][' stime ']== $v [' stime ']) {unSet ($arr 3[$i]);}} Remove ARR4 and $arr[0] (IsSet ($arr 4[$i)) {if ($arr 4[$i [' gid ']== $v [' gid '] and $arr 4[$i] [' Cod ']== $v [' cod '] and $arr 4 [$i] [' Tid1 ']== $v [' Tid1 '] and $arr 4[$i] [' Tid2 ']== $v [' Tid2 '] and $arr 4[$i] [' stime ']== $v [' stime ']) {unSet ($arr 4[$i]);}} Remove ARR5 and $arr[0] (IsSet ($arr 5[$i)) {if ($arr 5[$i [' gid ']== $v [' gid '] and $arr 5[$i] [' Cod ']== $v [' cod '] and $arr 5 [$i] [' Tid1 ']== $v [' Tid1 '] and $arr 5[$i] [' Tid2 ']== $v [' Tid2 '] and $arr 5[$i] [' stime ']== $v [' stime ']) {unSet ($arr 5[$i]);}}} UnSet ($max); $arr [1]= $arr 1;unset ($arr 1); $arr [2]= $arr 2;unset ($arr 2); $arr [3]= $arr 3;unset ($arr 3); $arr [4]= $arr 4; UnSet ($arr 4); $arr [5]= $arr 5;unset ($arr 5); Return $arr;}

http://www.bkjia.com/PHPjc/440321.html www.bkjia.com true http://www.bkjia.com/PHPjc/440321.html techarticle /** Number of collisions, find the re-overlapping value of multiple return: After the reorganization of the Array, as follows: $arr =array (0= ",//5 number of overlapping parts 1 =",//the 1th group minus [0] the value after 2 = ",//2nd Group ...

  • 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.