@ 2015-10-20T15:56:33Z <?php
$tz = new DateTimeZone('America/New_York');
$date_ranges = array(
'7 Days Ago' => array(
'from' => new DateTime('7 days ago 00:00:00', $tz),
'to' => new DateTime('yesterday 23:59:59', $tz)
),
'Yesterday' => array(
'from' => new DateTime('yesterday 00:00:00', $tz),
'to' => new DateTime('yesterday 23:59:59', $tz)
),
'30 Days Ago' => array(
'from' => new DateTime('30 days ago 00:00:00', $tz),
'to' => new DateTime('yesterday 23:59:59', $tz)
)
);
usort($myArray, function($a, $b) {
return $a['from']->getTimestamp() - $b['from']->getTimestamp();
});
print_r($date_ranges);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Fatal error: Uncaught TypeError: usort(): Argument #1 ($array) must be of type array, null given in /in/CrUN7:17
Stack trace:
#0 /in/CrUN7(17): usort(NULL, Object(Closure))
#1 {main}
thrown in /in/CrUN7 on line 17
Process exited with code 255 . Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 Fatal error: Uncaught TypeError: usort(): Argument #1 ($array) must be of type array, null given in /in/CrUN7:19
Stack trace:
#0 /in/CrUN7(19): usort(NULL, Object(Closure))
#1 {main}
thrown in /in/CrUN7 on line 19
Process exited with code 255 . Output for 5.4.30 - 5.4.45 , 5.5.14 - 5.5.38 , 5.6.0 - 5.6.40 , 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 Warning: usort() expects parameter 1 to be array, null given in /in/CrUN7 on line 19
Array
(
[7 Days Ago] => Array
(
[from] => DateTime Object
(
[date] => 2015-10-13 00:00:00.000000
[timezone_type] => 3
[timezone] => America/New_York
)
[to] => DateTime Object
(
[date] => 2015-10-19 23:59:59.000000
[timezone_type] => 3
[timezone] => America/New_York
)
)
[Yesterday] => Array
(
[from] => DateTime Object
(
[date] => 2015-10-19 00:00:00.000000
[timezone_type] => 3
[timezone] => America/New_York
)
[to] => DateTime Object
(
[date] => 2015-10-19 23:59:59.000000
[timezone_type] => 3
[timezone] => America/New_York
)
)
[30 Days Ago] => Array
(
[from] => DateTime Object
(
[date] => 2015-09-20 00:00:00.000000
[timezone_type] => 3
[timezone] => America/New_York
)
[to] => DateTime Object
(
[date] => 2015-10-19 23:59:59.000000
[timezone_type] => 3
[timezone] => America/New_York
)
)
)
Output for 5.4.0 - 5.4.29 , 5.5.0 - 5.5.13 Warning: usort() expects parameter 1 to be array, null given in /in/CrUN7 on line 19
Array
(
[7 Days Ago] => Array
(
[from] => DateTime Object
(
[date] => 2015-10-13 00:00:00
[timezone_type] => 3
[timezone] => America/New_York
)
[to] => DateTime Object
(
[date] => 2015-10-19 23:59:59
[timezone_type] => 3
[timezone] => America/New_York
)
)
[Yesterday] => Array
(
[from] => DateTime Object
(
[date] => 2015-10-19 00:00:00
[timezone_type] => 3
[timezone] => America/New_York
)
[to] => DateTime Object
(
[date] => 2015-10-19 23:59:59
[timezone_type] => 3
[timezone] => America/New_York
)
)
[30 Days Ago] => Array
(
[from] => DateTime Object
(
[date] => 2015-09-20 00:00:00
[timezone_type] => 3
[timezone] => America/New_York
)
[to] => DateTime Object
(
[date] => 2015-10-19 23:59:59
[timezone_type] => 3
[timezone] => America/New_York
)
)
)
preferences:dark mode live preview
313.24 ms | 406 KiB | 376 Q