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: 3.137.175.224
To prevent spam please submit by clicking the kitten: