src/Collection/ArrayCollection.php
public function last(?callable $predicate = null, $default = null)
    {
        if ($predicate === null) {
            return $this->isEmpty() ? $default : end($this->items);
        }

        foreach (array_reverse($this->items, true) as $key => $value) {
            if ($predicate($value, $key)) {
                return $value;
            }
        }

        return $default;
    }
public function last(?callable $predicate = null, $default = null)
    {
        if ($predicate === null) {
            return $this->isEmpty() ? $default : end($this->items);
        }

        foreach (array_reverse($this->items, true) as $key => $value) {
            if ($predicate($value, $key)) {
                return $value;
            }
        }

        return $default;
    }
public function last ( ? callable $ predicate = null , $ default = null ) { if ( $ predicate === null ) { return $ this -> isEmpty ( ) ? $ default : end ( $ this -> items ) ; } foreach ( array_reverse ( $ this -> items , true ) as $ key => $ value ) { if ( $ predicate ( $ value , $ key ) ) { return $ value ; } } return $ default ; }
Retrieves the last value from the collection

Optionally retrieves the last value that passes a truth test.

Predicate signature:

<code>
function ($value, $key): bool {}
</code>

@param callable|null $predicate The predicate function
@param mixed         $default   The default return value

@return mixed
Retrieves the last value from the collection