I'm looking for a PHP function that I think I have used before. I have two arrays: one main array of values, and one array of indexes. I want an easy way to keep all values whose index are in second the array, and remove the rest. So, I have already solved the problem by going through the array with a foreach loop like this:
$array = array("Foo", "Bar", "Foobar", "Test");
$indexlist = array(0, 2);
foreach($array as $index => $value) {
if(in_array($index, $indexlist)) {
$result[] = $value;
}
}
So my question is not how to solve the problem itself, but rather: is there a PHP function that does this? The question is based really only on curiosity because I think I remember that I used such a function earlier. The loop above results in the following output, which the requested function also should:
Array
(
[0] => Foo
[1] => Foobar
)
array_intersect_key()+ Justarray_flip()the indexlist array (Your output just is a bit weird.)