How can I re-arrange a array of objects like this:
[495] => stdClass Object ( [date] => 2009-10-31 18:24:09 ... ) [582] => stdClass Object ( [date] => 2010-2-11 12:01:42 ... ) ...
by the date
key, oldest first ?
To sort an array of objects by date property: Call the sort() method on the array. Subtract the date in the second object from the date in the first. Return the result.
To sort an array of objects by date in TypeScript: Call the sort() method on the array, passing it a function. The function will be called with 2 objects from the array. Subtract the timestamp of the date in the second object from the timestamp of the date in the first.
usort($array, function($a, $b) { return strtotime($a['date']) - strtotime($b['date']); });
Or if you don't have PHP 5.3:
function cb($a, $b) { return strtotime($a['date']) - strtotime($b['date']); } usort($array, 'cb');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With