3v4l.org

run code in 300+ PHP versions simultaneously
<?php $cars = [ 0 => ["id" => 1, "name" => "FORD"], 1 => ["id" => 2, "name" => "BMW"], 2 => ["id" => 3, "name" => "FIAT"], 3 => ["id" => 4, "name" => "RENAULT"], 4 => ["id" => 5, "name" => "BENTLEY"], ]; $selection = [ 0 => "1", 1 => "3", 2 => "4" ]; $cars_by_id = array_column($cars, null, 'id'); $selected_cars = array_intersect_key($cars_by_id, array_flip($selection)); var_dump($selected_cars);

preferences:
28.78 ms | 407 KiB | 5 Q