In this tutorial you will learn about the Laravel Arr random() function Example and its application with practical example.
Laravel Arr random() function Example
In this article, I’ll show you how to use laravel Arr random() function with example. We will show example of Arr random() function in laravel. In this tutorial, we will use Arr random() function to retrieve a random value from given array.
Laravel Arr::random method
The Arr::random method returns a random value from an array.
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 |
<?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 = ['Desk', 'Table', 'Chair']; $randomed1 = Arr::random($array1); print_r($randomed1); echo "<br>"; $array2 = ['php', 'laravel', 'html','css']; $randomed2 = Arr::random($array2); print_r($randomed2); } } |
Output:-
1 2 |
Table laravel |