3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $sum = 0; $master = array(); $arrColors = array('R', 'B', 'G' ,'Y'); $arrNumbers = array('1', '2', '3', '4'); foreach($arrNumbers as $num) { foreach($arrColor as $colorK => $colorV) { $temp = $colorV.' - '.$num; if ($num != $num[$colorK]) { $sum += $num; } array_push($master, $temp); } } print_r($master); echo "\n"; print_r ("The sum is ".$sum);
based on rc2ohH
Output for 5.1.0 - 7.1.0
Notice: Undefined variable: arrColor in /in/D22nK on line 8 Warning: Invalid argument supplied for foreach() in /in/D22nK on line 8 Notice: Undefined variable: arrColor in /in/D22nK on line 8 Warning: Invalid argument supplied for foreach() in /in/D22nK on line 8 Notice: Undefined variable: arrColor in /in/D22nK on line 8 Warning: Invalid argument supplied for foreach() in /in/D22nK on line 8 Notice: Undefined variable: arrColor in /in/D22nK on line 8 Warning: Invalid argument supplied for foreach() in /in/D22nK on line 8 Array ( ) The sum is 0
Output for 4.3.0 - 4.3.10, 4.4.0 - 5.0.5
Warning: Invalid argument supplied for foreach() in /in/D22nK on line 8 Warning: Invalid argument supplied for foreach() in /in/D22nK on line 8 Warning: Invalid argument supplied for foreach() in /in/D22nK on line 8 Warning: Invalid argument supplied for foreach() in /in/D22nK on line 8 Array ( ) The sum is 0
Output for 4.3.11
Array ( ) The sum is 0