Skip to content

Instantly share code, notes, and snippets.

@lutzissler
Created November 28, 2014 12:16
Show Gist options
  • Save lutzissler/537d4cee41690e3c0f76 to your computer and use it in GitHub Desktop.
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.
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