3v4l.org

run code in 300+ PHP versions simultaneously
<?php $item = [1,2,11, 4]; $products = [["id" => 1, "name" => "abc"], ["id" => 2, "name"=> "xyz"]]; // Get the ids of all products as an indexed array $prodIds = array_column($products, 'id'); // Check the id's that exists in both $existingIds = array_intersect($item, $prodIds); print_r($existingIds);
Output for 7.4.0 - 7.4.33, 8.0.1 - 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 ( [0] => 1 [1] => 2 )

preferences:
112.85 ms | 1236 KiB | 4 Q