This should work for you:
(With this solution you have an array with the id as key and the name as value)
<?php
$mainArray = array(
['id' => 1, 'name' => 'test'],
['id' => 2, 'name' => 'news'],
['id' => 3, 'name' => 'foo'],
['id' => 4, 'name' => 'bar']
);
$array = array(1,2,5,6,7);
$result = array();
foreach($mainArray as $k => $v)
$result[$v["id"]] = (array_intersect($mainArray[$k], $array) ? $mainArray[$k]["name"] : "");
$result = array_filter($result);
print_r($result);
?>
Output:
Array ( [1] => test [2] => news )
And you can easy go through the array an print every thing like this:
array_walk($result, function($value, $key) {
echo "Key: $key Value: $value <br />";
});
//OR
foreach($result as $key => $value)
echo "Key: $key Value: $value <br />";
Output:
Key: 1 Value: test
Key: 2 Value: news