Laravel Arr last() function Example

In this example, I explain Laravel Arr last() function Example. The laravel Arr last() function returns the last element of an array passing a given truth test. Also, we show how to use laravel array last() function.

Example : Laravel Arr::last() function


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;
use Illuminate\Support\Arr;

class UserController extends Controller
    public function index(){     
        $array = [100, 200, 300, 110];

        $last = Arr::last($array, function ($value, $key) {
            return $value >= 150;

        echo $last;




use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;

Route::get('users', [UserController::class,'index']);

I hope you understand laravel Array last() function and it can help you..