「PowerShell」foreachで配列の要素を取得するサンプル

2020年12月15日

書式
#foreach(変数名 in 配列)
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#数字配列
$cftArr =@(11,22,33,44,55,66)
echo "foreach digital result:"
foreach ($ele in $cftArr) {
echo $ele
}
echo "foreach string result:"
#文字列の配列
foreach ($cft in @("A01","B02","C03","D04")){
echo $cft
}
#数字配列 $cftArr =@(11,22,33,44,55,66) echo "foreach digital result:" foreach ($ele in $cftArr) { echo $ele } echo "foreach string result:" #文字列の配列 foreach ($cft in @("A01","B02","C03","D04")){ echo $cft }
#数字配列
$cftArr =@(11,22,33,44,55,66)

echo "foreach digital result:"
foreach ($ele in $cftArr) {
      
      echo $ele
}

echo "foreach string result:"
#文字列の配列
foreach ($cft in @("A01","B02","C03","D04")){
      echo $cft
}

実行結果
foreach digital result:
11
22
33
44
55
66
foreach string result:
A01
B02
C03
D04

PowerShell

Posted by arkgame