3v4l.org

run code in 300+ PHP versions simultaneously
<?php $cart = [ [ 'productID' => '11111' , 'size' => 'M' , 'quantity' => 2 ], [ 'productID' => '11111' , 'size' => 'L' , 'quantity' => 4 ], [ 'productID' => '22222' , 'size' => 'S' , 'quantity' => 3 ], [ 'productID' => '22222' , 'size' => 'L' , 'quantity' => 7 ], [ 'productID' => '33333' , 'size' => 'M' , 'quantity' => 1 ] ]; $r = removeElementFromArray( $cart , [ 'productID' => '11111' , 'size' => 'M' ] ); print_r($r); function removeElementFromArray($targetArray, $needles) { return array_filter($targetArray, function ($item) use ($needles) { return !empty(array_diff_assoc($needles, $item)); }); }
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Array ( [1] => Array ( [productID] => 11111 [size] => L [quantity] => 4 ) [2] => Array ( [productID] => 22222 [size] => S [quantity] => 3 ) [3] => Array ( [productID] => 22222 [size] => L [quantity] => 7 ) [4] => Array ( [productID] => 33333 [size] => M [quantity] => 1 ) )

preferences:
112.32 ms | 1622 KiB | 4 Q