3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $arr = array(400,500,600,700,800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000,2100,2200,2300,2400,2500,2600,2700,2800,2900,3000); $indexText = 'wIndex'; $valText = 'wVal'; for($i = 0; $i<count($arr); $i++) { if($i == 0) echo 'if('.$valText.' <= '.$arr[$i].') '.$indexText.' = '.$i.';<br>'; else echo 'if('.$valText.' > '.$arr[$i-1].' && '.$valText.' <= '.$arr[$i].') '.$indexText.' = '.$i.';<br>'; }
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
if(wVal <= 400) wIndex = 0;<br>if(wVal > 400 && wVal <= 500) wIndex = 1;<br>if(wVal > 500 && wVal <= 600) wIndex = 2;<br>if(wVal > 600 && wVal <= 700) wIndex = 3;<br>if(wVal > 700 && wVal <= 800) wIndex = 4;<br>if(wVal > 800 && wVal <= 900) wIndex = 5;<br>if(wVal > 900 && wVal <= 1000) wIndex = 6;<br>if(wVal > 1000 && wVal <= 1100) wIndex = 7;<br>if(wVal > 1100 && wVal <= 1200) wIndex = 8;<br>if(wVal > 1200 && wVal <= 1300) wIndex = 9;<br>if(wVal > 1300 && wVal <= 1400) wIndex = 10;<br>if(wVal > 1400 && wVal <= 1500) wIndex = 11;<br>if(wVal > 1500 && wVal <= 1600) wIndex = 12;<br>if(wVal > 1600 && wVal <= 1700) wIndex = 13;<br>if(wVal > 1700 && wVal <= 1800) wIndex = 14;<br>if(wVal > 1800 && wVal <= 1900) wIndex = 15;<br>if(wVal > 1900 && wVal <= 2000) wIndex = 16;<br>if(wVal > 2000 && wVal <= 2100) wIndex = 17;<br>if(wVal > 2100 && wVal <= 2200) wIndex = 18;<br>if(wVal > 2200 && wVal <= 2300) wIndex = 19;<br>if(wVal > 2300 && wVal <= 2400) wIndex = 20;<br>if(wVal > 2400 && wVal <= 2500) wIndex = 21;<br>if(wVal > 2500 && wVal <= 2600) wIndex = 22;<br>if(wVal > 2600 && wVal <= 2700) wIndex = 23;<br>if(wVal > 2700 && wVal <= 2800) wIndex = 24;<br>if(wVal > 2800 && wVal <= 2900) wIndex = 25;<br>if(wVal > 2900 && wVal <= 3000) wIndex = 26;<br>