Blogger Information
Blog 14
fans 1
comment 0
visits 4593
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP分支、循环与流程控制
叫我孙大树
Original
256 people have browsed it
<?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>';
}

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments