- print_r: documentation ( source)
- in_array: documentation ( source)
<?php
$a = array("test"=>"1", "test2"=>2, "test3"=>3);
$needed = array("test", "test2");
foreach($a as $i => $v) {
if(!in_array($i, $needed)) {
unset($a[$i]);
}
}
print_r($a);