Created
November 18, 2010 22:16
-
-
Save SeanJA/705759 to your computer and use it in GitHub Desktop.
extra array functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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