So far, you’ve seen the ways in which you can create and add to arrays. In this section, you will examine some of the tools PHP provides to allow you to acquire information about arrays and access their elements.
You can access an element of an array by using its index:
Because of the flexibility of arrays, however, you won’t always know how many elements a particular array contains. That’s where the count() function comes into play. count() returns the number of elements in an array. In the following code, we define a numerically indexed array and use count() to access its last element:
$users = array ("Bert", "Sharon", "Betty", "Harry" ); print $users[count($users)-1];