Hi friends.
I am currently reading through a php book and there is an array example which doesn't make any sense to me.
Basically, the code below echos the final element in the array, using the count() function to retrieve the last element of an indexed array:
$authors = array( “Steinbeck”, “Kafka”, “Tolkien”, “Dickens” );
$lastIndex = count( $authors ) - 1;
echo $authors[$lastIndex];
.............the above code is suppose to display 'Dickens'
I don' understand how adding the following:
-1
...... to the end of:
$lastIndex = count( $authors )
........... gets us the final element in the array??
Can someone explain?
Paul.