🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 一、*三目运算符 ``` $loggedIn = false; echo ($loggedIn) ? "you are logged in" : "you are not logged in"; ``` ## 二、php代码混合html代码时的语法糖 ``` <div> <?php if ($loggedIn) { ?> <h1>welcome to php world!</h1> <?php } else{ ?> <h1>hello you guys.</h1> <?php } ?> </div> ``` 语法糖形式,更美观: ``` <div> <?php if ($loggedIn): ?> <h1>welcome to php world!</h1> <?php else: ?> <h1>hello you guys.</h1> <?php endif; ?> </div> ``` ## 三、循环语法糖 ``` <div> <?php for($i = 0; $i < 10; $i++) ?> <li><?php echo $i."<br>";</li> <?php endfor; ?> </div> ``` ``` <?php $arr = ["jimson","lily","candy","alice"]; ?> <div> <?php foreach($arr as $val): ?> <?php echo $val."<br>"; <?php endforeach; ?> </div> ```