PHP syntax structure

Source: Internet
Author: User
Tags foreach

"PHP Syntax Structure Classification"

Cyclic structure, sequential structure and selection structure

One, circular statement

(1), Foreach Loop

Defined:

A foreach loop is used to iterate through all the items in a collection, the most typical set type is an array, and in a foreach loop, one or more commands are run against each item in the array

Syntax structure:

"Example, you need to loop through the values in the $string array."

$string = "Apple", "banana", "orange"

Foreach ($fruit in $string)

{

Write-host $fruit

}

"Example, to loop through the result set returned by the Get-childitem command"

Foreach ($file in Get-childitem c:\)

{

Write-host $file

}

(2), for loop

Defined:

A For loop is used to create a command that runs in a command block when a specified condition evaluates to True, and the typical use of a For loop is an array of values that are iterating through

Syntax structure:

"Example, looping through the number 1 to 10."

for ($i =1; $i-le; $i + +)

{Write-host $i}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.