Blogger Information
Blog 42
fans 5
comment 0
visits 38200
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php一周小结,流程,循环
张浩刚
Original
1004 people have browsed it

1、三元运算符

表达式?'值1':'值2';
表达式为真,值1;;;表达式为假,值二

$a = 100;
echo $a >= 90 ? '买' : '不买'; // --->买
echo $a >= 101 ? '买' : '不买'; // -->不买
可简写为:
echo $a ? '买' : '不买'; // --->买

$b = 0;
echo $b ? '买' : '不买'; // --》不买

2、判断 if else switch (值确定时用switch 不确定是用if else)

$a = 70;
if($a=100){
    echo '完美';
}elseif($a>=80){
    echo '不错';
}elseif($a>=60){
    echo '及格';
}else{
    echo '不及格';
}
================================
$b = 80;
switch($b){
    case $b = 100 : echo '完美';
    break;
    case $b >= 80 : echo '不错';
    break;
    case $b >= 60 : echo '及格';
    break;
    default : echo '不及格';
    break;
}

3、循环 for while (  do while )

for($a=1;$a<10;$a++){
    echo $a;
}
// 输出 123456789
===============================
$a = 1;
while($a<10){
    echo $a++;
}
// 输出 123456789
===============================
$num = 1;
do{
    $num++;
}while($num<1);
//do 先运行条件并执行,再看while 停止,结果为已经生成的 1;
===============================
continue
for($a=1;$a<10;$a++){
    if($a>4 && a<7){
        continue;
    }
    echo $a;
}
// 跳过7继续运行  结果 1234 789;跳过5 6

break
for($a=1;$a<10;$a++){
    if($a==7){
        break;
    }
    echo $a;
}
// 到7结束,结果:123456
===============================

微信图片_20191118123559.jpg

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:三元在php7中可简化为??
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
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!