Laravel Arr shuffle() function Example

The laravel Arr shuffle() function randomly shuffles the items in the array. In this example, I example how to use laravel array shuffle() function in laravel application. We will show how rearrange an array in random order in laravel.

Example : Laravel Arr::shuffle() Method

<?php

namespace App\Http\Controllers;

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

class UserController extends Controller
{
    public function index(){        


        $array = Arr::shuffle([1, 2, 3, 4, 5]);
        print_r($array);
        // [3, 2, 5, 1, 4] - (generated randomly)
    }
}

routes/web.php

<?php

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

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

I hope you understand laravel Arr::shuffle() function and it can help you…