Multidimensional Arrays
Multidimensional Arrays
We can even create multidimensional arrays i.e. arrays within arrays. We access values by providing an index for the array and another one for the value inside it.
Example:
Output:
We can also print the multi-dimensional array.
Example:
Output:
Use loops with arrays:
The simplest way of looping through an array is to use a simple for-each loop.
Example:
Output:
Alternatively, you can also use a simple for loop to do the same.
Example:
Output: