3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /* Default from the book */ $a = range(3,9); foreach ($a as $b) { switch($b) { case 3: $b = 7; case 7: $b = 3; default: // do nothing } } echo implode('-',$a) . PHP_EOL; // Excerpt From: Lorna Mitchell. “Zend Certification Preparation Pack.” iBooks. /* Suggested alternate method from the book */ $a = range(3,9); foreach ($a as $key => $b) { switch($b) { case 3: $a[$key] = 7; case 7: $a[$key] = 3; default: // do nothing } } echo implode('-',$a) - PHP_EOL; /* Second alternate by using $b by reference */ $a = range(3,9); foreach ($a as &$b) { switch($b) { case 3: $b = 7; case 7: $b = 3; default: // do nothing } } echo implode('-',$a);
based on IQKtM
Output for 7.1.0 - 7.2.0
3-4-5-6-7-8-9 Notice: A non well formed numeric value encountered in /in/DddcB on line 35 Warning: A non-numeric value encountered in /in/DddcB on line 35 33-4-5-6-3-8-9
Output for 5.0.2 - 7.0.4, 7.0.6 - 7.0.20
3-4-5-6-7-8-9 33-4-5-6-3-8-9
Output for 7.0.5
3-4-5-6-7-8-9 33-4-5-6-7-8-9
Output for 5.0.0 - 5.0.1
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/DddcB on line 17 3-4-5-6-7-8-9PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/DddcB on line 35 33-4-5-6-3-8-9
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /in/DddcB on line 41
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '&', expecting T_VARIABLE or '$' in /in/DddcB on line 41
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /in/DddcB on line 41
Process exited with code 255.