PHP中的分支及循环语句
2024-09-02 22:37:59
这次实践的都是PHP7的语法。
感觉是以前的5差别不是那么大,只是希望越来越快吧。
<?php $looking = isset($_GET['title']) || isset($_GET['author']) ?> <!DOCTYPE html> <html lang='en'> <head> <meta charset='UTF-8'> <title>BookStore</title> </head> <body> <?php echo "Befor the conditional.<br/>"; if (2 > 2) { echo "Inside the conditional.<br/>"; } elseif ( 2 == 2) { echo "Print when 2 == 2.<br/>"; } elseif ( 2 < 2) { echo "Not evaluted.<br/>"; } else { echo "Inside the else.<br/>"; } echo "After the conditional.<br/>"; $title = 'Harry Potter'; switch ($title) { case 'Harry Potter': echo 'Nice story. a bit too long.'; break; case 'Load of the Rings': echo 'A classic!'; break; default: echo 'Dunno that one.'; break; } echo "<br/>"; $i = 1; while ($i < 4) { echo $i . "<br/>"; $i++; } echo "<br/>"; $i = 1; do { echo $i . "<br/>"; $i++; } while ($i < 0); for ($i = 1; $i < 10; $i++) { echo $i . "<br/>"; } $names = ['Harry', 'Ron', 'Hermione']; for ($i = 0; $i < count($names); $i++) { echo $names[$i] . "<br/>"; } foreach ($names as $name) { echo $name . "<br/>"; } foreach ($names as $key => $name) { echo $key . ' -> ' . $name . "<br/>"; } ?> </body> </html>
输出:
Befor the conditional. Print when 2 == 2. After the conditional. Nice story. a bit too long. 1 2 3 1 1 2 3 4 5 6 7 8 9 Harry Ron Hermione Harry Ron Hermione 0 -> Harry 1 -> Ron 2 -> Hermione
最新文章
- JqueryUI Dialog 加载动态页 部分页
- 大话css之display的Block未解之谜(一)
- 自定义HttpModule的一些经验--配置篇
- C#枚举描述获取
- meta中的viewport指令
- rsync 不能同不子级目录的问题
- EF小节
- SecureCRT恢复默认字体
- POJ 1159 Palindrome 最长公共子序列的问题
- CF-Mr. Kitayuta&#39;s Colorful Graph
- C5-信号量与PV操作(iOS篇-细说信号量)
- 第六章 Hibernate关联映射
- 苹果系统css样式变化
- BZOJ 4569: [Scoi2016]萌萌哒 [并查集 倍增]
- WEB中间件--tomcat爆破,burp和python脚本
- 在IIS中如何配置SSL(https)
- vue当前路由跳转初步研究
- 重定向、feed输出:控制台输出的内容存放到文件
- Java中代码点与代码单元(转)
- 【原创】user.id字段