Created
April 5, 2019 05:18
-
-
Save Mika-/791d7096ae953d0dca3c824b12a97fcf to your computer and use it in GitHub Desktop.
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 | |
/** | |
* 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