Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative syntax for switch

Tags:

php

Hey there is an alternative syntax for switch statement in PHP, but this code doesn't work:

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

Parse error: syntax error, unexpected T_INLINE_HTML, expecting T_ENDSWITCH or T_CASE or T_DEFAULT in /path/to/file on line #

like image 719
Draex_ Avatar asked Aug 25 '12 08:08

Draex_


1 Answers

Solution for this problem is putting switch($variable): with case 1: into same block of PHP code:

<div>
<?php switch($variable): 
case 1: ?>
<div>
Newspage
</div>
<?php break;?>
<?php case 2: ?>
</div>
Forum
<div>
<?php break;?>
<?php endswitch;?>
</div>
like image 74
Draex_ Avatar answered Sep 22 '22 06:09

Draex_