3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $anna_array = array("soccer" => "10", "basketball" => "20", "atletics" => "40"); $john_array = array("soccer" => "15", "basketball" => "15", "atletics" => "45"); $common_sports = array_keys(array_intersect_key($anna_array, $john_array)); $points_anna_array = $points_john_array = array_fill_keys($common_sports, 0); foreach ($common_sports as $common_sport) { if ($anna_array[$common_sport] > $john_array[$common_sport]) { $points_anna_array[$common_sport]++; } else if ($anna_array[$common_sport] < $john_array[$common_sport]) { $points_john_array[$common_sport]++; } } echo $points_speler1_array[soccer]; foreach ($common_sports as $common_sport) { echo sprintf( 'Anna(%s) %d vs John(%s) %d'."\n", $common_sport, $points_anna_array[$common_sport], $common_sport, $points_john_array[$common_sport] ); }
based on EqFum
Output for 7.2.0
Warning: Use of undefined constant soccer - assumed 'soccer' (this will throw an Error in a future version of PHP) in /in/CrZed on line 17 Notice: Undefined variable: points_speler1_array in /in/CrZed on line 17 Anna(soccer) 0 vs John(soccer) 1 Anna(basketball) 1 vs John(basketball) 0 Anna(atletics) 0 vs John(atletics) 1
Output for 5.3.22 - 7.1.10
Notice: Use of undefined constant soccer - assumed 'soccer' in /in/CrZed on line 17 Notice: Undefined variable: points_speler1_array in /in/CrZed on line 17 Anna(soccer) 0 vs John(soccer) 1 Anna(basketball) 1 vs John(basketball) 0 Anna(atletics) 0 vs John(atletics) 1