3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr_dates = array(20150616,20150615,20150612,20150611,20150610,20150609,20150608,20150605,20150604,20150603,20150602,20150601,20150529,20150528,20150521,20150514,20150507,20150430,20150423,20150416,20150409,20150402,20150326); $current_date = 20150616; $expected_trend_date = 20150516; $expected_result = 20150514; $trend_index = 0; $last_diff = 100000; foreach ($arr_dates as $index => $date) { $diff = abs($date - $expected_trend_date); echo $diff, ':', $date, PHP_EOL; if ($diff < $last_diff) { $last_diff = $diff; } else { $trend_index = $index; break; } } echo $arr_dates[$trend_index];
Output for 4.3.10 - 4.3.11, 4.4.0 - 4.4.9, 5.0.2 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
100:20150616 99:20150615 96:20150612 95:20150611 94:20150610 93:20150609 92:20150608 89:20150605 88:20150604 87:20150603 86:20150602 85:20150601 13:20150529 12:20150528 5:20150521 2:20150514 9:20150507 20150507
Output for 4.3.0 - 4.3.9, 5.0.0 - 5.0.1
100:20150616 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL99:20150615 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL96:20150612 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL95:20150611 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL94:20150610 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL93:20150609 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL92:20150608 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL89:20150605 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL88:20150604 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL87:20150603 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL86:20150602 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL85:20150601 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL13:20150529 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL12:20150528 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL5:20150521 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL2:20150514 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL9:20150507 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/NGOXu on line 15 PHP_EOL20150507

preferences:
216.8 ms | 405 KiB | 378 Q