3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // convert decimal to base 2 without using base_convert or printf $base = 2; $decnum = 23; $num = 23; $stack = array(); while( $num > 0) { $arr[] = $num % $base; // store remainder in array $num = floor($num/$base); // no integer division } var_dump($arr); $wrong = join('',$arr); var_dump($wrong); $cat = join('',array_reverse($arr)); var_dump($cat); printf("%b\n",$decnum); echo base_convert(23,10,2); // now using the stack while( $decnum > 0) { array_push($stack,($decnum % $base)); // store remainder on stack $decnum = floor($decnum/$base); // no integer division } var_dump($stack); while($i=0,$max = count($stack);$i < $max; $i++) { echo array_pop($stack); } echo "\n";
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.4.26
Parse error: syntax error, unexpected ',' in /in/NXhLs on line 28
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected ',' in /in/NXhLs on line 28
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/NXhLs on line 28
Process exited with code 255.