3v4l.org

run code in 300+ PHP versions simultaneously
<?php $startDate = new \DateTimeImmutable('now'); $endDate = (new \DateTimeImmutable('now'))->add(new \DateInterval('P3D')); $dates = [ [ $startDate, $startDate->add(new \DateInterval('P0Y0M0DT3H')) ], [ $startDate->add(new \DateInterval('P0Y0M0DT1H')), $endDate ], [ $startDate->sub(new \DateInterval('P0Y0M0DT10H')), $startDate->sub(new \DateInterval('P0Y0M0DT8H')) ], ]; function showDates(iterable $dates): void { foreach($dates as $startEndDate) { var_dump($startEndDate[0]->format('Y/m/d H:i:s'), $startEndDate[1]->format('Y/m/d H:i:s')); } } function customSort(iterable $dates): iterable { return usort($dates, function($startEndDate1, $startEndDate2) { return $startEndDate1[0] < $startEndDate2; }); } showDates($dates); echo '----------------------- Ordered ---------------------------'; showDates(customSort($dates));
Output for 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
string(19) "2020/05/14 12:47:58" string(19) "2020/05/14 15:47:58" string(19) "2020/05/14 13:47:58" string(19) "2020/05/17 12:47:58" string(19) "2020/05/14 02:47:58" string(19) "2020/05/14 04:47:58" ----------------------- Ordered --------------------------- Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in /in/2QsR9 on line 29 Fatal error: Uncaught TypeError: customSort(): Return value must be of type Traversable|array, true returned in /in/2QsR9:31 Stack trace: #0 /in/2QsR9(36): customSort(Array) #1 {main} thrown in /in/2QsR9 on line 31
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 string(19) "2020/05/14 12:47:58" string(19) "2020/05/14 15:47:58" string(19) "2020/05/14 13:47:58" string(19) "2020/05/17 12:47:58" string(19) "2020/05/14 02:47:58" string(19) "2020/05/14 04:47:58" ----------------------- Ordered --------------------------- Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in /in/2QsR9 on line 29 Fatal error: Uncaught TypeError: customSort(): Return value must be of type Traversable|array, true returned in /in/2QsR9:31 Stack trace: #0 /in/2QsR9(36): customSort(Array) #1 {main} thrown in /in/2QsR9 on line 31
Process exited with code 255.
Output for 8.2.0 - 8.2.19
string(19) "2020/05/14 12:47:58" string(19) "2020/05/14 15:47:58" string(19) "2020/05/14 13:47:58" string(19) "2020/05/17 12:47:58" string(19) "2020/05/14 02:47:58" string(19) "2020/05/14 04:47:58" ----------------------- Ordered --------------------------- Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in /in/2QsR9 on line 29 Fatal error: Uncaught TypeError: customSort(): Return value must be of type Traversable|array, bool returned in /in/2QsR9:31 Stack trace: #0 /in/2QsR9(36): customSort(Array) #1 {main} thrown in /in/2QsR9 on line 31
Process exited with code 255.
Output for 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28
string(19) "2020/05/14 12:47:58" string(19) "2020/05/14 15:47:58" string(19) "2020/05/14 13:47:58" string(19) "2020/05/17 12:47:58" string(19) "2020/05/14 02:47:58" string(19) "2020/05/14 04:47:58" ----------------------- Ordered --------------------------- Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in /in/2QsR9 on line 31 Fatal error: Uncaught TypeError: customSort(): Return value must be of type iterable, bool returned in /in/2QsR9:31 Stack trace: #0 /in/2QsR9(36): customSort(Array) #1 {main} thrown in /in/2QsR9 on line 31
Process exited with code 255.
Output for 8.0.13
string(19) "2020/05/14 10:47:58" string(19) "2020/05/14 13:47:58" string(19) "2020/05/14 11:47:58" string(19) "2020/05/17 10:47:58" string(19) "2020/05/14 00:47:58" string(19) "2020/05/14 02:47:58" ----------------------- Ordered --------------------------- Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in /in/2QsR9 on line 31 Fatal error: Uncaught TypeError: customSort(): Return value must be of type iterable, bool returned in /in/2QsR9:31 Stack trace: #0 /in/2QsR9(36): customSort(Array) #1 {main} thrown in /in/2QsR9 on line 31
Process exited with code 255.
Output for 7.3.0 - 7.3.31, 7.3.33, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
string(19) "2020/05/14 12:47:58" string(19) "2020/05/14 15:47:58" string(19) "2020/05/14 13:47:58" string(19) "2020/05/17 12:47:58" string(19) "2020/05/14 02:47:58" string(19) "2020/05/14 04:47:58" ----------------------- Ordered --------------------------- Fatal error: Uncaught TypeError: Return value of customSort() must be iterable, bool returned in /in/2QsR9:31 Stack trace: #0 /in/2QsR9(36): customSort(Array) #1 {main} thrown in /in/2QsR9 on line 31
Process exited with code 255.
Output for 7.3.32, 7.4.26
string(19) "2020/05/14 10:47:58" string(19) "2020/05/14 13:47:58" string(19) "2020/05/14 11:47:58" string(19) "2020/05/17 10:47:58" string(19) "2020/05/14 00:47:58" string(19) "2020/05/14 02:47:58" ----------------------- Ordered --------------------------- Fatal error: Uncaught TypeError: Return value of customSort() must be iterable, bool returned in /in/2QsR9:31 Stack trace: #0 /in/2QsR9(36): customSort(Array) #1 {main} thrown in /in/2QsR9 on line 31
Process exited with code 255.
Output for 7.2.0 - 7.2.33
string(19) "2020/05/14 12:47:58" string(19) "2020/05/14 15:47:58" string(19) "2020/05/14 13:47:58" string(19) "2020/05/17 12:47:58" string(19) "2020/05/14 02:47:58" string(19) "2020/05/14 04:47:58" ----------------------- Ordered --------------------------- Fatal error: Uncaught TypeError: Return value of customSort() must be iterable, boolean returned in /in/2QsR9:31 Stack trace: #0 /in/2QsR9(36): customSort(Array) #1 {main} thrown in /in/2QsR9 on line 31
Process exited with code 255.

preferences:
156.48 ms | 402 KiB | 183 Q