| Viewed 13 times

How to sorts an array by its values in laravel


How to sorts an array by its values in laravel

1 Answer
Mohammad Qandeel
Answered
0

You can use the sort() helper function to sorts an array by its values in laravel

For Laravel developers, you can reorder the array element by its value. 

If you want to sorts an array by its values in laravel you can use the sort() helper function which will return a new array 

Example of how to use sort() helper function

use Illuminate\Support\Arr;

$array = ['Photo', 'Table', 'Chair'];

$sorted = Arr::sort($array);

Output

=> [
     2 => "Chair",
     0 => "Photo",
     1 => "Table",
   ]

 


Related FAQ