There's an answer here: Combine two array and order this new array by date
It explains how two arrays can be merged and then sorted by date.
function cmp($a, $b){
$ad = strtotime($a['date']);
$bd = strtotime($b['date']);
return ($ad-$bd);
}
$arr = array_merge($array1, $array2);
usort($arr, 'cmp');
the solution looks quite elegant, but I'm confused by
return ($ad-$bd);
I mean there's no comparison operator, it just subtracts
function newFunc($a, $b) {
return($a-$b);
}
echo newFunc(5,3);
returns 2
So how does this actually indicate how to sort the arrays?
Update:
I read further the documentation on the usort page as suggested. Does it perform this subtraction with each of the elements? Does it iterate through each array element and subtracts it from other elements? Just trying to wrap my head around this.