Please tell me how to return multiple intersections of two arrays in PHP.

problem description

there are three arrays, as follows:

$result[0] = ["17", "38", "12", "40"];
$result[1] = ["47", "18", "24", "22"];
$result[2] = ["01", "28", "18", "38"]; 

or merge together. You can have duplicate values:

$result = ["17", "38", "12", "40", "47", "18", "24", "22", "01", "28", "18", "38"];

I"ve tried to convert an array into a string using preg_match_all () to match, but it doesn"t correspond to $numbers. I really can"t think of any way. Please help me. Thank you.

Php
Apr.02,2021

ideas:

  1. confirm the location of matchArr in oddEven, such as 1mem10 and 20
  2. according to the location obtained above, take out the data in number, and finally splice
  3. .

implementation:

$numbers = ['17', '38', '12', '40', '20', '47', '45', '22', '02', '19', '29', '10', '27', '41', '26', '47', '18', '24', '22', '27', '33', '47', '25', '09', '16', '32', '01', '28', '18', '38'];


// 
$oddEven = ['1', '2', '2', '2', '2', '1', '1', '2', '2', '1', '1', '2', '1', '1', '2', '1', '2', '2', '2', '1', '1', '1', '1', '1', '2', '2', '1', '2', '2', '2'];
$oddEvenStrs = implode("", $oddEven);

// 
$matchArr = ['1', '2', '2', '2'];
$matchArrStrs = implode("", $matchArr);

var_dump($oddEvenStrs);
var_dump($matchArrStrs);

    var_dump(count($numbers));

function findIt($from, $find, $numbers, $pos) 
{
    $result = '';
    $pos = strpos($from, $find, $pos);
    if ($pos !==  false) {
        $result .= implode(",", array_slice($numbers, $pos, 4));
        $pos += 4;
    }
    
    if (count($numbers) > $pos)
    {
        return $result . "," . findIt($from, $find, $numbers, $pos);
    }
    
    return $result;
}

$result = findIt($oddEvenStrs, $matchArrStrs, $numbers, 0);

echo $result;

var_dump(explode(",", $result));

 $matchArrString = implode($matchArr, ',');//1,2,2,2
        $oddEvenString = implode($oddEven, ',');//1,2,2,2,2,1,1,2,2,1,1,2,1,1,2,1,2,2,2,1,1,1,1,1,2,2,1,2,2,2

        $strlen = strlen($matchArrString);//
        //$matchArrString  $oddEvenString
        $strpos_1 = strpos($oddEvenString, $matchArrString);
        $offset_1 = $strlen+$strpos_1;//
        $strpos_2 = strpos($oddEvenString, $matchArrString, $offset_1);//2
        $offset_2 = $strlen+$strpos_2;//2
        $strpos_3 = strpos($oddEvenString, $matchArrString, $offset_2);//3

        //
        $index_2 = count(explode(',', substr($oddEvenString, 0, $strpos_2)))-1;
        $index_3 = count(explode(',', substr($oddEvenString, 0, $strpos_3)))-1;

        $count = count($matchArr);
        for ($i=0; $i < $count; $iPP) { 
            $numbers_1[$i] = $numbers[$strpos_1+$i];
        }
        for ($i=0; $i < $count; $iPP) { 
            $numbers_2[$i] = $numbers[$index_2+$i];
        }
        for ($i=0; $i < $count; $iPP) { 
            $numbers_3[$i] = $numbers[$index_3+$i];
        }
        print_r($numbers_1);
        echo '<br/>';
        print_r($numbers_2);
        echo '<br/>';
        print_r($numbers_3);
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3a12e-2c1da.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3a12e-2c1da.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?