使用php将php插入的方法


<?php if($a == $b){?>
<?php
if ($a % 2 == 1):
    echo "ほしい";
?>
<?php }?>


//It seems to me, that many people think that

<?php if ($a == 5): ?>
A ist gleich 5
<?php endif; ?>

//is only with alternate syntax possible, but 

<?php if ($a == 5){ ?>
A ist gleich 5
<?php }; ?>

//is also possible.

//alternate syntax makes the code only clearer and easyer to read


//If you wan't to use the alternative syntax for switch statements this won'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>

//Instead you have to workaround like this:

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