3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $result=<<<TXT 1 5 7 2 6 9 a c z TXT; $stat=array("odd"=>0,"even"=>0,"invalid"=>array()); foreach(explode("\n",$result) as $r) { $r=trim($r);// in case input is separated by \r\n if(!is_numeric($r)) { $stat["invalid"][]=$r; } elseif($r%2==0) { $stat["even"]+=intval($r); } else { $stat["odd"]+=intval($r); } } echo "Odd: ".$stat["odd"]."\n"; echo "Even: ".$stat["even"]."\n"; echo "Invalid: ".implode(" ",$stat["invalid"]);
Output for 4.3.0 - 7.2.6
Odd: 22 Even: 8 Invalid: a c z