3v4l.org

run code in 300+ PHP versions simultaneously
<?php $DoB1 = '14/01/02'; $DoB1match = preg_match("/([0-2]\d|3[0-1])\/(0\d|1[0-2])\/\d{2}/", $DoB1); // Check pattern $age1 = DateTime::createFromFormat('d/m/y', $DoB1) ->diff(new DateTime('now')) ->y; // Check age $age1OK = $age1 > 4 && $age1 < 14; // Check age greater than 4 but less than 14 $DoB1Valid = $DoB1match && $age1OK; if ($age1OK == true) { echo 'yeah'; } else { echo 'nah'; }
Output for 5.4.2 - 5.4.45, 5.6.28, 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
yeah
Output for 5.5.24 - 5.5.35, 5.6.7 - 5.6.21, 7.0.0 - 7.0.6
nah

preferences:
195.13 ms | 402 KiB | 227 Q