PHP数组搜索和删除

I have two array:

Array 1:

Array ( [0] => Array ( [id] => et1 [supplier_id] => 4 [supplier_product_code] => 00054X [is_active] => 1 ) 
[1] => Array ( [id] => et2 [supplier_id] => 4 [supplier_product_code] => 000558 [is_active] => 1 ) 
[2] => Array ( [id] => et3 [supplier_id] => 5 [supplier_product_code] => 00054X [is_active] => 1 ));

Array 2:

Array ( [0] => Array ([id] => et1 [same_sku] => et3);

I need to delete all the same_skus in array1 from array2.

So from my result array I need array1 to be:

Array ( [0] => Array ( [id] => et1 [supplier_id] => 4 [supplier_product_code] => 00054X [is_active] => 1 ) 
[1] => Array ( [id] => et2 [supplier_id] => 4 [supplier_product_code] => 000558 [is_active] => 1 ));

Code that I have right now does not work.

public function search_array($array, $val)
    {
        foreach ($array as $key => $row)
        {
            if ($row['id'] === $val) 
            {
                      return $key;
            }
        }
    }

foreach($array2->result() as $row)
        {
            $id = $row->id;
            $same_sku = $row->same_sku;

            $key = $this->search_array($array1, $id); 

            if(!empty($key))
            {
                $same_sku_key = $this->search_array($array1, $same_sku);
                if(!empty($same_sku_key))
                    unset($array1[$same_sku_key]);
            }
        }

In the following code I have recreated the two arrays from your example. I then created a function that removes from a haystack array (array1) all of the sub arrays that have an "id" that matches the value of "same_sku" within a needle array (array2). The final line echos the result array.

EDIT I have modified the original answer to pass the array values by reference and unset the unwanted sub arrays, instead of passing by value, looping, and returning another array. This should resolve the memory issue, as well as the other issue mentioned in your comment.

$array1 = array(
    array(
        'id'                    => 'et1',
        'supplier_id'           => '4',
        'supplier_product_code' => '00054X',
        'is_active'             => '1'
    ),
    array(
        'id'                    => 'et2',
        'supplier_id'           => '4',
        'supplier_product_code' => '000558',
        'is_active'             => '1'
    ),
    array(
        'id'                    => 'et3',
        'supplier_id'           => '5',
        'supplier_product_code' => '00054X',
        'is_active'             => '1'
    ),
    array(
        'id'                    => 'et4',
        'supplier_id'           => '5',
        'supplier_product_code' => '00054X',
        'is_active'             => '1'
    )
);

$array2 = array(
    array(
        'id'                    => 'et1',
        'same_sku'              => 'et3'
    ),
    array(
        'id'                    => 'et2',
        'same_sku'              => 'et4'
    )
);


function remove_same_sku(&$haystack, &$needles){

    foreach($needles as $needle){

        foreach($haystack as $key => $val){

            if($val['id'] === $needle['same_sku']){

                unset($haystack[$key]);

            }

        }

    }


}

remove_same_sku($array1, $array2);
echo print_r($array1);