3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $digits = array(9,8,7,6,5,4,3,2,1); $primes = array(2,3,5,7,11); function simplify(Int $num, Int $denom, Array $primes){ //going from high primes to low primes foreach(array_reverse($primes) as $prime) { if (($num % $prime == 0) && ($denom % $prime == 0)) { return [$num / $prime,$denom / $prime]; } } return [$num,$denom]; } echo "simplify 10:4 = " . implode(':',simplify(10,4,$primes)) . "\n"; echo "simplify 121:22 = " . implode(':',simplify(121,22,$primes)) . "\n"; echo "simplify 5:5 = " . implode(':',simplify(5,5,$primes)) . "\n";
based on 56HsL
Output for hhvm-3.18.5 - 3.22.0, 7.0.30 - 7.3.0beta1
simplify 10:4 = 5:2 simplify 121:22 = 11:2 simplify 5:5 = 1:1
Output for 5.6.30
Catchable fatal error: Argument 1 passed to simplify() must be an instance of Int, integer given, called in /in/TuTqV on line 16 and defined in /in/TuTqV on line 5
Process exited with code 255.