Skip to content
Advertisement

How to sort array with other arrays by date and take a limit in laravel and carbon

I have this array with other 16 arrays

JavaScript

and so on…

enter image description here

I want to sort the main array by date specified in “meta_date” field included on each “child” array, the sort can be $sort= "asc" or $sort= "desc"

and

I want to take a dynamic limit for the main array, for example if $limit=10 take the first 10 arrays sorted by date selected

currently, I’m using PHP 7.3 and laravel 8

Advertisement

Answer

Laravel’s collections come with everything you need:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement