How to get Random Value from Array in laravel

In this example, I will show how to get random value from array in laravel. Laravel Arr::random() function is use to get random value from array.

Example : Get random value from Array


namespace App\Http\Controllers;

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

class UserController extends Controller
    public function index(){        
        $array1 = [10,20,30,40,50,60];

        $randomed1 = Arr::random($array1);

        echo '<br>';
        $array2 = ['php', 'laravel', 'html','css'];

        $randomed2 = Arr::random($array2);




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

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

I hope you understand how to get random value from array and it can help you…