I have two arrays one contains ids that's going to check if it exists on the second array which is an associative array:
Array 1: [1,2,11, 4]
Array 2:
[["id" => 1, "name" => "abc"], ["id" => 2, "name"=> "xyz"]]
Currently using a nested foreach to iterate over and match them but I wanted to know if there was anything more efficient as the arrays will be a lot larger.
$item = [1,2,11, 4];
$data = [["id" => 1, "name" => "abc"], ["id" => 2, "name"=> "xyz"]];
foreach($items as $item)
{
foreach($data as $key => $products)
{
foreach($products as $product)
{
if($product['id'] == $item)
{
echo $product['name'];
}
}
}
}
Had a look at this and this but none really fit my scenario.
Any help appreciated.