Jump to content

Multiple ifs


ItsWesYo

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/75158-multiple-ifs/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/75158-multiple-ifs/#findComment-380118
Share on other sites

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.