Blogger Information
Blog 8
fans 0
comment 0
visits 11616
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php控制结构
BlogofDaniel
Original
783 people have browsed it

php控制逻辑

三种:顺序、分支、循环

顺序:自上而下,从左往右

分支:选择判断,分支

单分支(双分支):程序执行的流程不超过两个

多分支:两个以上

结构1:

if(表达式){

代码块;

}

else{

代码块;

}

*elseif和else if都能通过,等效

结构2:

switch($变量名){

case 值1:代码块;break;

case 值2:代码块;break;

case 值2:代码块;break;

default:代码块;

}

*

break:跳出代码

continue:跳出某一次循环,进入下一次循环

exit:停止当前脚本(调试)

if和switch的区别:

1.if判断区间,switch判断具体的数值

2.switch效率较高

循环:

while - 只要指定的条件成立,则循环执行代码块

do...while - 首先执行一次代码块,然后在指定的条件成立时重复这个循环

for - 循环执行代码块指定的次数

foreach - 根据数组中每个元素来循环代码块

格式1:

for(初始值;循环条件;改变变量){

代码块;

}

格式2:

while(条件){

代码块;

}

格式3:

do

{

要执行的代码;

}

while (条件);

格式4(数组):

foreach ($array as $key=>$value)

{

要执行代码;

}


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!