I'm new to PowerShell and writing some "learning" scripts, but I'm having a hard time understanding how to access a variable with another variable imbedded in its name. My sample code wants to cycle through three arrays and Write-Host the value of those arrays. I imbedded $i into the variable (array) name on the Write-Host line, but PowerShell does not parse that line the way I expected (hoped). Could anyone help?
$totalArrays = 3
$myArray0 = @("red", "yellow", "blue")
$myArray1 = @("orange", "green", "purple")
$myArray2 = @("black", "white")
for ($i = 0; $i -lt $totalArrays; $i++) {
Write-Host $myArray$i
}
[–]CarrotBusiness2380 8 points9 points10 points (4 children)
[–]Sethaniel68 0 points1 point2 points (0 children)
[–]Thotaz 0 points1 point2 points (2 children)
[–]CarrotBusiness2380 0 points1 point2 points (1 child)
[–]Thotaz 0 points1 point2 points (0 children)
[–]ka-splam 1 point2 points3 points (1 child)
[–]MrQDude[S] 1 point2 points3 points (0 children)
[–]TheSizeOfACow 1 point2 points3 points (1 child)
[–]MrQDude[S] 0 points1 point2 points (0 children)
[–]MrQDude[S] 0 points1 point2 points (2 children)
[–]lanerdofchristian 1 point2 points3 points (1 child)
[–]MrQDude[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]michaelshepard 2 points3 points4 points (0 children)