There is an amazing and simple default laravel solution for this.
$collection = collect([
["Plastic and cosmetic surgery",90],
["Dermatology surgery",121],
["Infertility",134],
["Gynecology surgery",191],
["Hair transplant",92],
["Bariatrics and weight loss surgery",117],
["Dentistry",88]
]);
$sorted = $collection->sortBy(1);
$data = $sorted->values()->all();
dd($data);
Output
array:7 [▼
0 => array:2 [▼
0 => "Dentistry"
1 => 88
]
1 => array:2 [▼
0 => "Plastic and cosmetic surgery"
1 => 90
]
2 => array:2 [▼
0 => "Hair transplant"
1 => 92
]
3 => array:2 [▼
0 => "Bariatrics and weight loss surgery"
1 => 117
]
4 => array:2 [▼
0 => "Dermatology surgery"
1 => 121
]
5 => array:2 [▼
0 => "Infertility"
1 => 134
]
6 => array:2 [▼
0 => "Gynecology surgery"
1 => 191
]
]
You can check more functions like this in the documentation. I hope you will enjoy this solution.