3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function calculateLevels( $total, $totalPerLevel = 2, $iteration = 0 ) { if( $total <= 1 ) { return $iteration; } else { if ( $totalPerLevel === 1 ) { $total--; } return calculateLevels( (int) ( $total / $totalPerLevel ), $totalPerLevel, $iteration + 1 ); } } $x = 15; echo "$x - " .calculateLevels( $x,2 ) . "\n"; $x = 15; echo "$x - " .calculateLevels( $x,5 ) . "\n"; $x = 15; echo "$x - " .calculateLevels( $x,3 ) . "\n"; $x = 15; echo "$x - " .calculateLevels( $x,1 ) . "\n"; $x = 15; echo "$x - " .calculateLevels( $x,8 ) . "\n"; $x = 15; echo "$x - " .calculateLevels( $x,20 ) . "\n";
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.13.2, 7.0.0 - 7.1.0
15 - 3 15 - 2 15 - 2 15 - 14 15 - 1 15 - 1