作者:Aliot
发布时间:2017-07-02
评论:0
阅读:0
【PHP语法结构分类】
循环结构、顺序结构、选择结构
一、循环语句
(1)、 Foreach循环
定义:
Foreach循环用来遍历一个集合中的所有项,最典型的集合类型是数 组,在Foreach循环中,会针对数组中的每一项运行一个或多个命令
语法结构:
![]()
【例,需要循环显示$string数组中的值】
$string="apple","banana","orange"
Foreach($fruit in $string)
{
write-Host $fruit
}
【例,要循环显 示Get-ChildItem命令返回的结果集合】
Foreach($file in Get-ChildItem c:)
{
write-Host $file
}
(2)、For循环
定义:
For循环 用来创建在某一指定条件的计算结果为True时运行命令块中的命令,For循环的典型用法为 循 环访问的值数组
语法结构:
![]()
【例,循环显示1到10的数】
For ($i=1; $i -le 10; $i++)
{ write-Host $i }