i want to find the same numbers from the following multidimensional array


    <?php
    declare(strict_types=1);
    
    $multiArr = [
        [
            [12, 32, 13, 34],
            [13, 12, 23, 41],
            [15, 23, 34, 45],
        ],
        [
            [122, 32, 133, 314],
            [123, 132, 23, 141],
            [155, 23, 334, 465],
        ],
        [
            [12, 342, 135, 234],
            [713, 712, 423, 431],
            [15, 23, 34, 45],
        ],
        [
            [12, 372, 913, 334],
            [13, 162, 243, 341],
            [175, 423, 34, 435],
        ],
    ];
    
    
    
    function pre(array $y)
    {
        echo "<pre>";
        print_r($y);
        echo "</pre>";
    }
    
    
    
    function same_value($multiArr, $index)
    {
        $row_index = $index; // 0
        $commonNumbers = [];
        $a = []; // per result 
       
        $firstSubarray = $multiArr[$row_index];
        // pre($firstSubarray );
       
        foreach ($firstSubarray as $subInnerkey => $innerArray) {
    
            //                        0        12  
            foreach ($innerArray as $key => $number) {
                $isCommon = false;
                // echo $number;
    
                // checking======================================
                for($i = 0; $i < count($multiArr); $i++) {
    
                    $found = false;
                    // pre($multiArr[$i]);
                    foreach ($multiArr[$i] as $subCheckKey => $subInnerArray) {
                       
                        //    pre($subInnerArray);
                                     1
                        // echo $subInnerkey ."__".$subCheckKey."<br>";
                        if ($subInnerkey != $subCheckKey) {
                            // echo $number. "<br>";
    
                            if (in_array($number, $subInnerArray)) {
                                $found = true;
                                 $a = [$number => $subInnerArray];
                                array_push($commonNumbers, $a);
                                break;
                            }
                        }
                    }
                }
            }
        }
    
        return $commonNumbers;
    }
    
    $result = same_value($multiArr, 1);
    pre($result);
    
    ?>

This is the output

 Array
(
    [0] => Array
        (
            [23] => Array
                (
                    [0] => 15
                    [1] => 23
                    [2] => 34
                    [3] => 45
                )

        )

[1] => Array
    (
        [23] => Array
            (
                [0] => 155
                [1] => 23
                [2] => 334
                [3] => 465
            )

    )

[2] => Array
    (
        [23] => Array
            (
                [0] => 15
                [1] => 23
                [2] => 34
                [3] => 45
            )

    )

[3] => Array
    (
        [23] => Array
            (
                [0] => 13
                [1] => 12
                [2] => 23
                [3] => 41
            )

    )

[4] => Array
    (
        [23] => Array
            (
                [0] => 123
                [1] => 132
                [2] => 23
                [3] => 141
            )

    )

[5] => Array
    (
        [334] => Array
            (
                [0] => 12
                [1] => 372
                [2] => 913
                [3] => 334
            )

    )
)

can anyone tell me where I made a mistake in this code ??

firstly I select one value of the subarray skip that array selected value of the array and compare all other elements if that element repeats in any other subarrays in checking loops then it will push that array with that element into a new array

then problem appears it may skip some value which is also repeated in subarrays

I don’t know where I made a mistake can someone help me

function same_value($multiArr, $index)

this function is selected index whome have three subarray then one by one

select value and check all other siblings arrays also

function pre($a) this function just print array at the end of the result

the algorithm i mostly use here selection and sort but I only used selection part in this program

this is array inside is subarrays

[
        [12, 32, 13, 34],
        [13, 12, 23, 41],
        [15, 23, 34, 45],
]