Jagged Arrays

by Jul 9, 2012

This may not be for everyone: have a look at how you can create "jagged arrays". Here's a jagged array which really is a nested array:

PS> $array = 1,2,3,(1,('a','b'),3),5

It has five elements, and element #3 (start counting by 0) is an array itself which in turn holds a third array in element #1.

Check out its behavior:

PS> $array[2]
3

PS> $array[3]
1
a
b
3

PS> $array[3][0]
1

PS> $array[3][1]
a
b

PS> $array[3][1][0]
a

PS> $array[3][1][1]
b

Twitter This Tip! ReTweet this Tip!