PHP: Get first and last elements of an array

I often need to grab the first or last element of an array. This method works for either numeric or associative arrays.

$array = array('cats','dogs','fish','horses','squids');

$last  = end($array);   # 'squids'
$first = reset($array); # 'cats'


Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
 
Logged IP: 18.218.2.191
To prevent spam please submit by clicking the kitten: