Here are two examples:
Copy Code code as follows:
$array =7..10
foreach ($n in $array)
{
$n * $n
}
#49
#64
#81
#100
foreach ($file in dir c:\windows)
{
if ($file. LENGTH-GT 1MB)
{
$File. Name
}
}
#explorer. exe
#WindowsUpdate. Log
This is just to demonstrate foreach, but the sec
) theWrite-host 2.8The filter gets all the number items after the first number within 10 that can be divisible by 3, and includes the first number that can be divisible by 3 -(1..10). Where ({$_% 3-eq0}, [System.Management.Automation.WhereOperatorSelectionMode]::skipuntil) WuWrite-host 2.9The filter gets all the number items after the first number within 10 that can be divisible by 3, and includes the first number that can be divisible by 3, but only the first 3 digits -(1..10). Where ({$_% 3-eq
Helper Service, is processid more than 100:true
Name:application Identity, are processid more than 100:true
Name:application information, are processid more than 100:true
Name:application Management, are processid more than 100:false
Name:ASP.NET state Service, are processid more than 100:false
Combining conditional processing
Foreach-object processing can contain arbitrary PowerShell scr
the end, and the inner pointer of the original array points to the end of the array.
echo $age, '
Run the example output:
283035Array ([Wang] [li] = [Zhang] + 25)
To modify the original array element in foreach, you can do so by reference, changing the example above to:
Run the example output:
182025 Array ([Wang] [li] = [Zhang] + 35)
Traversing multidimensional arrays
The foreach syntax structure
; ...; ENDfor;
Other languages have a foreach statement to iterate over an array or hash list, and PHP is ok (see foreach). In PHP 3, you can combine the list () and each () function with a while loop to achieve the same effect. See the documentation for these functions for examples.
2. Foreach LoopPHP 4 (not PHP 3) in
In PHP, the foreach loop statement is used to traverse arrays cyclically. This chapter introduces a special loop statement in PHP, "foreach" loop statement.
What is foreach loop used?
Bytes
Foreach loop syntax format
The foreach loop syntax can be written in either of the f
!!!!------------------------------Simply say foreachIts format is such a foreach (array name as Subscript = = value)The subscript is the top $a[1], where 1 is the subscript of the array!Here you should understand, why is $a[$key] such outputYou remember that no matter how it changes, the output method of the array is always $a[1], not $a[' language '.================================================================There are two ways to use
This article describes using wildcards to find strings in PowerShell, and uses the LIKE operator with wildcard characters.
The wildcard characters in PowerShell are the asterisk (*) and question mark (?), which is the same as in the DOS system. To find in a string using wildcard characters, you can use the LIKE operator. Examples are as follows:
"123" is starte
Applies to PowerShell 3.0 or later,Although it is not recommended to Hard-code passwords in script files, there are still scenarios that are not. Compared to hard coding in a plain text way, we can also take a little bit of thought and confuse the passwords. Although confusing passwords is a very low-level protection, but for people who do not know PowerShell, or more mysterious.
The next script asks the u
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.