Jump to content

[SOLVED] the if statement


gazever

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.