- print_r: documentation ( source)
- array_filter: documentation ( source)
- in_array: documentation ( source)
<?php
$years = [7,8,9];
$students = [
20=>7,
21=>11,
420=>8,
52=>12,
55=>9
];
$students = array_filter($students, function($year) use ($years) {
return in_array($year, $years);
});
print_r($students);