企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## 一、*三目运算符 ``` $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> ```