For example, if you have a variable $a that refers to the array
[10, 20, 30] you use
$a[1] to reference the element value 20. If you try to access an element that does not exist, i.e. by using an index outside the range of the array, an error is generated.
You can also access elements in an array by using the #foreach directive to loop over the array elements. For example:
To reference an element in an array in an array you must add the index of the second array to the reference. For example, if you have the variable
$b that refers to the array
[1, [4, 5], 3] you use
$b[1][0] to reference the element value 4.
If the array contains several levels of arrays you must add the indexes of all levels to the reference. For example, if you have the variable
$c that refers to the array
[1, [4, [6, 8]], 3] you use
$c[1][1][0] to reference the element value 6.
The variable $index must return an integer, otherwise an error is generated.