3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $default = ['c2'=>0,'c3'=>0,'c4'=>0,'c5'=>0]; $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); }); $totals = array_fill_keys(array_keys($students), $default); print_r($totals);
based on 4QCUm
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0beta1
Array ( [20] => Array ( [c2] => 0 [c3] => 0 [c4] => 0 [c5] => 0 ) [420] => Array ( [c2] => 0 [c3] => 0 [c4] => 0 [c5] => 0 ) [55] => Array ( [c2] => 0 [c3] => 0 [c4] => 0 [c5] => 0 ) )