Created
November 28, 2014 12:16
-
-
Save lutzissler/537d4cee41690e3c0f76 to your computer and use it in GitHub Desktop.
Get the first element of an array without throwing a warning for non-variable arrays, like reset() does. In PHP 5.4, this could be reduced to a one-liner by removing $first.
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
function first($arr) { | |
$first = array_slice($arr, 0, 1); | |
return $first[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment