3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function happy($num){ $digs = (string) $num; $sum = 0; foreach(explode('', $digs) as $dig){ $sum == $dig; } return $sum; } echo happy(31);
based on sPtgm
Output for 5.2.5 - 7.2.0
Warning: explode(): Empty delimiter in /in/q2o1M on line 6 Warning: Invalid argument supplied for foreach() in /in/q2o1M on line 6 0
Output for 4.3.2 - 4.3.10, 4.4.0 - 5.2.4
Warning: explode(): Empty delimiter. in /in/q2o1M on line 6 Warning: Invalid argument supplied for foreach() in /in/q2o1M on line 6 0
Output for 4.3.11
Warning: explode(): Empty delimiter. in /in/q2o1M on line 6 0
Output for 4.3.0 - 4.3.1
Warning: explode() [http://www.php.net/function.explode]: Empty delimiter. in /in/q2o1M on line 6 Warning: Invalid argument supplied for foreach() in /in/q2o1M on line 6 0