gazever Posted February 22, 2007 Share Posted February 22, 2007 With the if statement, is it possible to use if as shown in the example below, if ($i == 9, 18, 27, 36 etc.) {do something} rather than using lots of else ifs? if ($i == 9) { echo '<td>'.$array[$i].'</td></tr> <tr>'; } else if ($i == 18) { echo '<td>'.$array[$i].'</td></tr> <tr>'; } Thanks Gaz Link to comment https://forums.phpfreaks.com/topic/39615-solved-the-if-statement/ Share on other sites More sharing options...
ryanh_106 Posted February 22, 2007 Share Posted February 22, 2007 if ($i == 9 || $i == 18 || $i == 27 || ..... etc) echo '<td>'.$array[$i].'</td></tr><tr>'; seems the best way from what you said, you could also use case statements, or, depending on how many values there are, create an array and test for membership... $values = array(9, 18, 27, 36, etc); if (in_array($i, $values)) echo '<td>'.$array[$i].'</td></tr><tr>'; Hope this helps Ryan Link to comment https://forums.phpfreaks.com/topic/39615-solved-the-if-statement/#findComment-191183 Share on other sites More sharing options...
gazever Posted February 22, 2007 Author Share Posted February 22, 2007 Thats perfect thanks, I have it working at present using lots of ( else ifs, seemed silly, Thanks Gaz Link to comment https://forums.phpfreaks.com/topic/39615-solved-the-if-statement/#findComment-191190 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.