一、php 条件判断
if语句:
$i = 8000;
if ($i<=8000){
echo '买台电脑';
}else{
echo '洗洗睡吧';
};
执行结果:

手抄作业:

if else语句:
$var = 8000;
if($var >= 10000){
echo '我要买个iphone xs max';
}else if($var >= 8000){
echo '我要买个iphone xs';
}else if($var >= 6000){
echo '我要买个iphone xr';
}else if($var >= 4000){
echo '我只能买个小米手机';
}else{
echo '我洗洗睡了';
};
执行结果:

手抄作业

switch语句
$var = 3000;
switch ($var) {
case $var >= 10000:
echo '我要买个iphone xs max';
break;
case $var >= 8000:
echo '我要买个iphone xs';
break;
case $var >= 6000:
echo '我要买个iphone xr';
break;
case $var >= 4000:
echo '我只能买个小米手机';
break;
default:
echo '我洗洗睡了';
break;
};
执行结果

手抄作业

while语句
$int = 1;
while ( $int < 10 ) {
echo $int;
echo '<hr/>';
$int ++;
}
执行结果

手抄作业

do while语句
$int = 1;
do {
echo $int;
echo '<hr>';
$int++;
}while ( $int < 1);
执行结果

手抄作业

for语句
for( $int=1; $int<10; $int++){
echo $int;
echo '<hr>';
}
执行结果

手抄作业

continue跳过当前循环,进入下一个循环
for( $int=1; $int<10; $int++){
if($int == 5){
//结束当前循环,进入下次循环
continue;
};
var_dump($int);
echo '<hr>';
}
执行结果

手抄代码

在for中加入判断
for( $int=1; $int<10; $int++){
echo $int;
if($int == 8){
echo '比较特殊';
}
echo '<hr>';
}
执行结果

手抄代码

break
for( $int=1; $int<10; $int++){
if($int == 5){
//结束当前循环
break;
}
var_dump($int);
echo '<hr>';
}
执行结果

手抄代码
