Skip to content

Instantly share code, notes, and snippets.

@Mika-
Created April 5, 2019 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mika-/791d7096ae953d0dca3c824b12a97fcf to your computer and use it in GitHub Desktop.
Save Mika-/791d7096ae953d0dca3c824b12a97fcf to your computer and use it in GitHub Desktop.
<?php
/**
* Get first element from array
*
* @param array $array
* @return mixed|null
*/
function array_first(array $array)
{
$key = array_key_first($array);
if ($key) {
return $array[$key];
}
return null;
}
/**
* Get last element from array
*
* @param array $array
* @return mixed|null
*/
function array_last(array $array)
{
$key = array_key_last($array);
if ($key) {
return $array[$key];
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment