Laravel Arr sort() function Example

Laravel 8 , Laravel 7 , Laravel , Laravel 6

Nicesnippets

328

13-03-2021


Hi Guys,

In this blog,I will explain you how to work laravel array sort() function. We will show example of array sort function to get array sort element value in laravel.The Arr::sort method sorts an array by its values.

Here, I will give you full example for simply Arr sort() method in laravel as bellow.

Example


<?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'];

$sorted1 = Arr::sort($array1);

print_r($sorted1);

//['Chair', 'Desk', 'Table']

$array2 = ['php', 'laravel', 'html','css'];

$sorted2 = Arr::sort($array2);

print_r($sorted2);

//['css','html', 'laravel', 'php']

}

}

Output

['Chair', 'Desk', 'Table']

['css','html', 'laravel', 'php']

It Will help you...


Recommended Posts