Skip to content

Instantly share code, notes, and snippets.

@SeanJA
Created November 18, 2010 22:16
Show Gist options
  • Save SeanJA/705759 to your computer and use it in GitHub Desktop.
Save SeanJA/705759 to your computer and use it in GitHub Desktop.
extra array functions
<?php
/**
* return the first element of the array
* @note If you are in a foreach loop, this will not reset the pointer to the first element of the array like calling reset($myarray) would
* @see reset
* @param array $array The array
* @return mixed the first element of the array
*/
function array_first(array $array){
$first = reset($array);
return $first;
}
/**
* return the last element of the array
* @note If you are in a foreach loop, this will not set the pointer to the last element of the array like simply end($myarray) would
* @see end
* @param array $array The array
* @return mixed the last element of the array
*/
function array_last(array $array){
$last = end($array);
return $last;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment