karimali831 Posted April 14, 2012 Share Posted April 14, 2012 Hey can someone use their intelligence and teach me how to change the below if statements to a loop? if($h_rows) { $rl_rows = 8; } elseif($g_rows) { $rl_rows = 7; } elseif($f_rows) { $rl_rows = 6; } elseif($e_rows) { $rl_rows = 5; } elseif($d_rows) { $rl_rows = 4; } elseif($c_rows) { $rl_rows = 3; } elseif($b_rows) { $rl_rows = 2; } elseif($a_rows) { $rl_rows = 1; } Thanks Link to comment https://forums.phpfreaks.com/topic/260952-if-to-loop/ Share on other sites More sharing options...
MMDE Posted April 14, 2012 Share Posted April 14, 2012 Here you go: <?php for($i=8; $i>0; $i--){ if(${chr($i+96).'_rows'}){ $rl_rows = $i; break; } } ?> It does exactly what you want, but it's really bad coding, not because of what I did, but because of what you wanted. Should probably have been an array in the first place. If they are all set on the server side, and they are all booleans, I guess its okay, but else you probably want to use isset. Link to comment https://forums.phpfreaks.com/topic/260952-if-to-loop/#findComment-1337418 Share on other sites More sharing options...
karimali831 Posted April 14, 2012 Author Share Posted April 14, 2012 Thanks alot, I'll keep in mind what you said Link to comment https://forums.phpfreaks.com/topic/260952-if-to-loop/#findComment-1337421 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.