Hoda Kh
Hoda Kh

Reputation: 355

sorting collection in alphabetical order in laravel

I want to sort two laravel collection after merging them in alphabetical order, I've used the following code:

$result = $commonTitles->merge($newTitles)->sort();

And the result is sorted A to Z and then a to z.

["Ask","Black","Unit","ab","live","test"]

The result that I expect is sorting as A a to z Z. How can I change the result?

Upvotes: 0

Views: 188

Answers (1)

Rémy
Rémy

Reputation: 355

Try:

$result = $commonTitles->merge($newTitles)->sort(SORT_NATURAL | SORT_FLAG_CASE);

Upvotes: 2

Related Questions