ItsWesYo Posted October 29, 2007 Share Posted October 29, 2007 I'm making a tutorial/guide for a site. There are multiple chapters (1, 2, 3, 4, etc). Instead of making multiple ifs, is there a way I can put the unfinished ones in a single line. Hard to explain :\ Part of guide.php <?php $page = $_REQUEST['i']; if($page == "chap1"){ echo (" <b>CHAPTER 1</b> is not available right now. "); die(); } ?> Like, I also want chap2 and chap3 to be unavailable too without making a new if($page) statement. Quote Link to comment https://forums.phpfreaks.com/topic/75158-multiple-ifs/ Share on other sites More sharing options...
darkfreaks Posted October 29, 2007 Share Posted October 29, 2007 <?php $page = $_REQUEST['i']; if($page == "chap1"|$page == "chap2"|$page == "chap3"){ echo (" <b>Chapters 1-3</b> are not available right now. "); die(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/75158-multiple-ifs/#findComment-380115 Share on other sites More sharing options...
kenrbnsn Posted October 29, 2007 Share Posted October 29, 2007 You could also use a switch() statement: <?php if (isset($_REQUEST['i'])) switch ($_REQUEST['i'])) { case 'chap1': case 'chap2': case 'chap3': echo '<span style="font-weight:bold;color:red">Chapters 1 - 3 are not available yet</span>'; break; case 'chap4': // // do other stuff // break; } } ?> Not one line, but easier to change. Ken Quote Link to comment https://forums.phpfreaks.com/topic/75158-multiple-ifs/#findComment-380118 Share on other sites More sharing options...
kratsg Posted October 29, 2007 Share Posted October 29, 2007 <?php $page = $_REQUEST['i']; $unfinished = array("chap1","chap2","chap3"); if(!in_array($page,$unfinished)){die("<b>CHAPTER 1</b> is not available right now.");} ?> Is.. that what you mean? :-o Quote Link to comment https://forums.phpfreaks.com/topic/75158-multiple-ifs/#findComment-380119 Share on other sites More sharing options...
teng84 Posted October 29, 2007 Share Posted October 29, 2007 for($x=1;$x<=10;x++){ $chapter='chapter'.$x; if ($page = $chapter){ echo $chapter.' is not available'; } } check ten chapter Quote Link to comment https://forums.phpfreaks.com/topic/75158-multiple-ifs/#findComment-380122 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.