First of all you should realize that the above code creates a one element array that contains a reference to a 4 element array. The square brackets indicate that you are creating or returning a reference to an array so you end up with a three dimensional array. You probably intended to use ("w", "h", [1, 2], "c") which would give a two dimensional array. Your code is perfectly legal, but probably not what you expected.
So with your original code $array[0] will contain a reference to a four element array. To look at the first element in this array, you have properly dereferenced it by using the -> operator and that is why $array[0]->[0] returns "w".
Now $array[0]->[2] contains a reference to your embedded array, so to access the the elements of this array, you must dereference again, by using the -> operator again. So $array[0]->[2]->[0] contains the number 1 and $array[0]->[2]->[1] contains the number 2.
The reason you are seeing ARRAY(0x1770fa) when you print $array[0]->[2] is because that contains the reference to the array [1, 2]. The value that a reference contains is the memory location of the actual array that it points to, and that is what is printed out.
Just remember that [] always returns an array reference and needs to be dereferenced to access it.
In reply to Re: Multi dimensional arrays
by cees
in thread Multi dimensional arrays
by phatbasturd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |