Reputation: 1069
So say I have 2 arrays.
$Letters = ("A","B","C")
$Numbers = ("1","2","3")
How would you construct a foreach loop such that this worked:
foreach ($letter in $letters) {set-something $number} where I could do a pair of values such that
A
was set to 1
, B
was set to 2
, C
was set to 3
, and so on. What is this even called? I thought it was called nested loops, but searching all over and it seems like that is NOT what this is called. Many thanks!
Upvotes: 0
Views: 72
Reputation: 201602
If it is a Zip op then this will do the trick:
C:\PS> $Letters | Foreach {$i=0} {@($_,$Numbers[$i++]}
A
1
B
2
C
3
But I think you might want this:
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
Upvotes: 4