配列・連想配列
配列の作成
カンマによる簡単な方法
PS> $nums = 1,2,3
PS> $nums[1]
2
@(;)による方法
PS> $texts = @("taro"; "jiro"; "hanako")
PS> $texts[1]
jiro
連想配列の作成 @{;}
PS> $gender = @{"taro" = "man"; "jiro" = "man"; "hanako" = "woman"}
PS> $gender["jiro"]
man
配列の追加・削除など
push
PS> $nums = 1,2,3
PS> $nums += 4
PS> $nums[3]
4
shift
PS> $nums = 1,2,3
PS> $first, $rest = $nums
PS> $first
1
PS> $rest
2
3
削除
PS> $nums = 1,2,3
PS> $nums[1] = $null
PS> $nums
1
3
挿入
PS> [System.Collections.ArrayList]$nums = 1,2,3
PS> $nums.Insert(1,9)
PS> $nums
1
9
2
3
多次元配列
PS> $data = ("taro", 15), ("jiro", 10)
PS> $data[1][1]
10
PS> $data = @{"taro" = @{"gender" = "man"; "age" = 15}; "hanako" = @{"gender" = "woman"; "age" = 12}}
PS> $data["hanako"]["age"]
12