In this tutorial you will learn about the Laravel Arr last() function Example and its application with practical example.
Laravel Arr last() function Example
In this article, I’ll show you how to use laravel Arr last() function with example. We will show example of Arr last() function in laravel. In this tutorial, we will use Arr last() function to return last element of an array passing a given truth test.
Laravel Arr::last method
The Arr::last method returns the last element of an array passing a given truth test.
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Controllers\FileController; use Illuminate\Support\Arr; class HomeController extends Controller { /** * Show the application dashboard. * * @return \Illuminate\Contracts\Support\Renderable */ public function index() { $array1 = Arr::last([100, 200, 300,250], function ($value, $key) { return $value >= 150; }); print_r($array1); echo "<br>"; $array2 =Arr::last([5, 8, 11,9], function ($value, $key) { return $value >= 5; }); print_r($array2); } } |
Output:-
1 2 |
250 9 |