From 36087e53753acbcdd54811e4ba03f57f594e5bb0 Mon Sep 17 00:00:00 2001 From: Cosmologist Date: Fri, 9 Nov 2018 21:20:57 +0300 Subject: [PATCH] Add ArrayType::first --- src/Gears/ArrayType.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Gears/ArrayType.php b/src/Gears/ArrayType.php index ac99af3..a213509 100644 --- a/src/Gears/ArrayType.php +++ b/src/Gears/ArrayType.php @@ -381,4 +381,20 @@ public static function unsetColumn($array, $column) return $array; } + + /** + * Get the first element of an array + * + * @param array $array The input array. + * + * @return mixed|null + */ + public static function first($array) + { + if (count($array) === 0) { + return null; + } + + return reset($array); + } } \ No newline at end of file