3v4l.org

run code in 300+ PHP versions simultaneously
<?php $intj = 5; $arrformfields[$intj][3] = 'ok'; $arrformfields[$intj][18] = 'ok2'; ${$arrformfields[$intj][3]} = '1990'; ${$arrformfields[$intj][18]} = 4; $value = '1989;1950'; $arrvalidrules = explode(';', $value); // On vérifie qu'il n'y bien que deux valeurs. if (count($arrvalidrules) == 2) { $arrvarlabels = array('intyearstart', 'intyearend'); foreach ($arrvarlabels as $key => $label) // On va définir l'année de départ et de fin. { if ($arrvalidrules[$key]!='') // On a définit une valeur dans la règle. { if (is_numeric($arrvalidrules[$key])) // Valeur numérique fixe. { ${$label} = intval($arrvalidrules[$key]); } else if (strpos($arrvalidrules[$key], 'Y') === 0) // Valeur selon l'année actuelle. { ${$label} = date('Y'); if (($intsignpos = strpos($arrvalidrules[$key], '+')) !== false) // On vérifie si on souhaite faire une adition. { ${$label} += intval(trim(substr($arrvalidrules[$key], $intsignpos+1))); } else if (($intsignpos = strpos($arrvalidrules[$key], '-')) !== false) // On vérifie si on souhaite faire une soustraction. { ${$label} -= intval(trim(substr($arrvalidrules[$key], $intsignpos+1))); } } else // On a saisit une valeur erroné (du texte) on définit la valeur comme par défaut. { ${$label} = ($key == 0 ? str_pad(0, ${$arrformfields[$intj][18]}, '0') : null); } } else // Définition de la valeur par défaut (annéeDeb = 0, annéeFin = null). { ${$label} = ($key == 0 ? str_pad(0, ${$arrformfields[$intj][18]}, '0') : null); } } if ($intyearend !== null) { if ( (($intyearstart > $intyearend) && (${$arrformfields[$intj][3]} < $intyearend OR ${$arrformfields[$intj][3]} > $intyearstart)) OR ${$arrformfields[$intj][3]} < $intyearstart OR ${$arrformfields[$intj][3]} > $intyearend ) { if ($intyearstart > $intyearend) { // L'année de début > à la fin, on change les valeurs. $intswitch = $intyearstart; $intyearstart = $intyearend; $intyearend = $intswitch; } $strerrormessage.="Le champ '".$arrformfields[$intj][1]."' est invalide, la valeur doit être comprise entre ".$intyearstart." et ".$intyearend." !<br />"; } } else if (${$arrformfields[$intj][3]} < $intyearstart) { $strerrormessage.="Le champ '".$arrformfields[$intj][1]."' est invalide, la valeur doit être comprise entre ".$intyearstart." et ".$intyearend." !<br />"; } } echo 'Date : '.$intyearstart.' - '.$intyearend;
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Warning: Undefined array key 1 in /in/lGPNm on line 62 Warning: Undefined variable $strerrormessage in /in/lGPNm on line 62 Date : 1950 - 1989
Output for 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.6 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined offset: 1 in /in/lGPNm on line 62 Notice: Undefined variable: strerrormessage in /in/lGPNm on line 62 Date : 1950 - 1989
Output for 7.3.32 - 7.3.33
Date : 1950 - 1989
Output for 5.0.4 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Notice: Undefined offset: 1 in /in/lGPNm on line 62 Notice: Undefined variable: strerrormessage in /in/lGPNm on line 62 Date : 1950 - 1989
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.3
Notice: Undefined offset: 1 in /in/lGPNm on line 62 Notice: Undefined variable: strerrormessage in /in/lGPNm on line 62 Date : 1950 - 1989

preferences:
295.66 ms | 402 KiB | 378 Q