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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.