Code Demon Code Demon - 5 months ago 11x
PHP Question

sort array base on its object value tha contains timestamp

first I query 2 different queries.

$first = first::where('id',$request->first_id)->select('name','created_at')->get();
$second = second::where('id', $request->second_id)->select('name','created_at')->get();

and then merge the two arrays

$data_combine = array_merge($first->toArray(), $second->toArray());

Now, I want to sort ascending the combine array base on there 'created_at' value, e.g '2016-05-06 16:43:46'. Any help, ideas, clues, recommendation, suggestions please?

$array = array_values(array_sort($data_combine , function ($value) {
    return $value['created_at'];

You can sort your merged array using array_sort function.