<?php //实例演示分支 $score = 88; if ($score >= 90 && $score <= 100) { echo '优'; } elseif ($score >= 80 && $score < 90) { echo '良'; } elseif ($score >= 60 && $score < 80) { echo '一般哦'; } elseif ($score >= 0 && $score < 60) { echo '差'; } else { echo 'Unkonow Score'; } //该段代码输出值为'良' //switch使用(elseif语法糖) $scoreSwitch = -2; switch ($scoreSwitch) { case $scoreSwitch >= 90 && $scoreSwitch <= 100: echo '优'; break; case $scoreSwitch >= 80 && $scoreSwitch < 90: echo '良'; break; case $scoreSwitch >= 60 && $scoreSwitch < 80: echo '一般'; break; case $scoreSwitch >= 0 && $scoreSwitch < 60: echo '差'; break; default: echo '输入内容不合法'; break; } //此段代码返回值为'输入内容不合法' //实例演示循环 //foreach $competitor = ['幼儿组','儿童组','少年组','青年组']; echo '<ul>'; foreach ($competitor as $group){ echo '<li>'.$group.'</li>'; } echo '</ul>'; //for for ($i=0;$i<=4;$i++){ echo $i.'<br>'; }
运行实例 »
点击 "运行实例" 按钮查看在线实例