February 2019
Intermediate to advanced
626 pages
15h 51m
English
Individual elements from an array may be selected using an index. The index counts from 0 to the end of the array. The first and second elements are available using index, 0 and 1:
$myArray = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 $myArray[0] $myArray[1]
In a similar manner, array elements can be accessed counting backward, from the end. The last element is available using the -1 index, and the penultimate element using the -2 index, for example:
$myArray[-1] $myArray[-2]
Ranges of elements may be selected either going forward (starting from 0) or going backward (starting with -1):
$myArray[2..4] $myArray[-1..-5]
More than one range can be selected in a single statement:
$myArray[0..2 + 6..8 + -1]
This requires ...
Read now
Unlock full access