简体   繁体   中英

php Is there a way to use switch statement for 3 or more cases

Is there a way to use switch statement for 3 or more cases?

<div>
<?php switch($variable): 
case 1: ?>
<div>
Newspage
</div>
<?php break;?>
<?php case 2: ?>
</div>
Forum
<div>
<?php break;?>
<?php case 3: ?>
</div>
Blogs
<div>
<?php break;?>
<?php endswitch;?>
</div>

because I get expected statement error message.

because I get expected statement error message.

I'm guessing you get unexpected switch error messages?

In that case you have not completed an earlier statement (or have syntax-errors). We need more code in any case.

switch($variable):  should be

switch($variable){

It opens and closes with a bracket. See http://www.w3schools.com/php/php_switch.asp for correct syntax.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM