Data sorting with php

Asked

Viewed 107 times

2

I need to sort an array by a specific "order" field, where within that array I have banners objects with the id, order, name and img fields. I need to sort this array in order. the order banner 0 needs to come in first, 1 in second and so on.

  • Have example of this array? If yes put the question.

1 answer

2


You can use the sortBy method of a Collection, for this, create a Collection object from the array and sort:

$collection = collect($array)->sortBy('ordem');

I hope it helps.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.