所以说我有2个数组。
$Letters = ("A","B","C")
$Numbers = ("1","2","3")
您将如何构造一个foreach循环,使其有效:
foreach ($letter in $letters) {set-something $number} where I could do a pair of values such that
A
设置为1
,B
设置为2
,C
设置为3
,依此类推。这甚至叫什么?我以为它被称为嵌套循环,但到处搜索,这似乎并不是所谓的嵌套循环。非常感谢!
最佳答案
如果是Zip op,则可以解决问题:
C:\PS> $Letters | Foreach {$i=0} {@($_,$Numbers[$i++]}
A
1
B
2
C
3
但我认为您可能想要这样:
C:\PS> $Letters | Foreach {$i=0;$ht=@{}} {$ht."$_"=$Numbers[$i++]}
C:\PS> $ht.A
1
C:\PS> $ht.B
2
C:\PS> $ht.C
3
关于loops - Powershell多个阵列(菜鸟),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19963919/