php - Sorting of array in laravel -


i have 2 array this.

 $array5 = json_decode('[{"time":"12:08 pm","md5":1201},{"time":"01:00 pm","md5":1121},{"day":"03:03 pm","md5":1401},{"time":"03:36 pm","md5":1334}]  ',true);  $array6 = json_decode('[{"time":"12:08 pm","ips":20},{"time":"01:00 pm","ips":10},{"time":"03:02 pm","ips":12},{"time":"03:36 pm","ips":11}]', true); 

combined array using array_merge_recursive is:

[{"time":"12:08 pm","url":1201,"ips":20},{"time":"01:00 pm","url":1121,"ips":10},{"time":"03:03 pm","url":1401},{"time":"03:36 pm","url":1334,"ips":11},{"time":"03:02 pm","ips":12}]  

now want sort array according time.is there possible way sort array according time?

you may use laravel array_sort helper method https://laravel.com/docs/5.4/helpers#method-array-sort

to avoid errors during comparison, use dates carbon opjects http://carbon.nesbot.com/docs/

$array = array_values(array_sort($array, function ($value) {     return new carbon($value['time']); })); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -