3v4l.org

run code in 300+ PHP versions simultaneously
<?php function testCode($voucher) { $eternalCodes = array( 'SNOWFALL', 'SASCREWS236C', 'FREELOAD5RTPYG', 'MCCOCT8J6WA', 'RKM6SH7UB', ); $temporaryCodes = array( 'SASCREWS236C' => array( 'from' => '2018-01-30', 'to' => '2018-12-31', ), 'SASAPRCQ4CD' => array( 'from' => '2018-04-01', 'to' => '2018-05-01', ), 'SASJUN8A39N' => array( 'from' => '2018-06-01', 'to' => '2018-07-01', ), 'SASJUL3NU24' => array( 'from' => '2018-07-01', 'to' => '2018-08-01', ), 'SASAUGWX4ZV' => array( 'from' => '2018-08-01', 'to' => '2018-11-01', ), ); $time = time(); foreach ($temporaryCodes as $code => $dates) { if ($voucher === $code && strtotime($dates['from'].' 00:00:00') <= $time && $time <= strtotime($dates['to'].' 23:59:59')) { return true; } } if (in_array($voucher, $eternalCodes, true) === true) { return true; } return false; } var_dump(testCode('SASAPRCQ4CD'));

preferences:
47.34 ms | 405 KiB | 6 Q