public static function first($array, $n = 1, $guard = false)
    {
        if (empty($array))
            return;

        if ($n <= 0)
            throw new \UnexpectedValueException("invalid number of items $n");

        $result = [];
        static::each($array, function ($item) use (& $n, & $result) {
            $result[] = $item;

            if (--$n == 0)
                return static::BREAKER;
        });

        return $guard || isset($result[1]) ? $result : $result[0];
    }
public static function first($array, $n = 1, $guard = false)
    {
        if (empty($array))
            return;

        if ($n <= 0)
            throw new \UnexpectedValueException("invalid number of items $n");

        $result = [];
        static::each($array, function ($item) use (& $n, & $result) {
            $result[] = $item;

            if (--$n == 0)
                return static::BREAKER;
        });

        return $guard || isset($result[1]) ? $result : $result[0];
    }
public static function first ( $ array , $ n = 1 , $ guard = false ) { if ( empty ( $ array ) ) return ; if ( $ n <= 0 ) throw new \ UnexpectedValueException ( "invalid number of items $n" ) ; $ result = [ ] ; static :: each ( $ array , function ( $ item ) use ( & $ n , & $ result ) { $ result [ ] = $ item ; if ( -- $ n == 0 ) return static :: BREAKER ; } ) ; return $ guard || isset ( $ result [ 1 ] ) ? $ result : $ result [ 0 ] ; }
Returns the first element of an array. Passing n will return the first n elements of the array. Passing guard
will force the returned value to be an array.

@category Array Functions

@param traversable $array the list of items
@param int $n optional, the number of items to pick
@param bool $guard optional, true to always return an array

@throws UnexpectedValueException if $n is negative or zero

@return mixed,array
Returns the first element of an array . Passing n will return the first n elements of the array . Passing guard will force the returned value to be an array .