Laravel Arr sort() function Example

In this example, I explain Laravel Arr sort() function. The laravel Arr::sort() function sorting array by its self. We will show example of laravel array sorting. Laravel Arr::sort function same work as array_sort() php function. I explain step by step how to sort an assocoative array in laravel.

In this post, we will learn how to sorting array using Arr::sort() function in laravel.

Read Also :  Laravel Migration Add Comment to Column Example

Example : Laravel Arr::sort() function

<?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 = ['Desk', 'Table', 'Chair'];

        $sorted = Arr::sort($array);
        print_r($sorted);
        // ['Chair', 'Desk', 'Table']
    }
}

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 sort() function and it can help you…