php的替代语法

替代语法是将php中左大括号变更冒号;右大括号变更为对应的endif | endwhile |endswitch| endforeach;

1.0 if ...endif;

//替代语法
<?php if ($a == 5): ?>
<h1>a==5</h1>
<?php else($a==6):?>
<h1>a==6</h1>
<?php endif; ?>


//原生语法
<?php if ($a == 5){ ?>

<?php else($a==6){?>

<?php }; ?>

2.0 while ...endwhile;

<?php while():?>
html
<?php endwhile;?>

3.0 foreach ...endforeach

<?php foreach($arr as $item):?>
html
<?php endforeach;?>

4.0 switch...endswitch (you need to pay special attention);

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

猜你喜欢

转载自blog.csdn.net/pinming_sanlang1990/article/details/81165939