How come the code <?php print "contents: $arr[1]"; ?> Works, but <?php print "contents: $arr[1][2]"; ?> Doesn't for two-dimensional array of mine?
Answer Posted / Nimmi Gupta
The reason is that you are trying to access a nested element in your array. In PHP, arrays are zero-indexed, so if you have a two-dimensional array and you want to access the second row and third column, you should use $arr[1][2], not $arr[1][3]. The 0-based indexing causes an error when you try to access elements outside of the defined range.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers