我想将网站上注册参与者的年龄限制为16岁及以上使用php我有if语句
if ($DOBYear === '1999' && $DOBMonth === 'November'|| 'December') {
echo('You have to be at least 16 years to register');
}
这似乎不起作用,因为当选择11月或12月作为$DOBMonth
值时它回应'你需要至少16年注册',无论$DOBYear
是否是 static void Main (string[] args) {
string directoryPath = @"F:\logs";
using (StreamWriter file = new StreamWriter(@"f:\development\testing.txt", true)) {
foreach (string rawImagePath in Directory.GetFiles(directoryPath, "*.log").Select(Path.GetFullPath)) {
//image.ReadHeaderLessImage(rawImagePath, width, height, colorOrder, bpp);
/*
List<MacbethCheckerBatchesColor> resultWithOutExtraLines =
wrapper.DetectMacbethColorChecker(image.Data, image.Width, image.Height, image.ColorOrder,
image.Bpp, showResult, batchFillFactor);
*/
//if (resultWithOutExtraLines == null) {
file.WriteLine(rawImagePath);
//}
}
}
}
}
1999年与否。我怎样才能使两个变量相互依赖。
答案 0 :(得分:2)
将支票更改为以下内容:
if ($DOBYear === '1999' && ($DOBMonth === 'November'|| $DOBMonth === 'December'))
所以你可以肯定它需要是那一年和其中一个月。
更好的方法是计算年龄,并检查:
$ageDt = new DateTime($age);
$nowDt = new DateTime();
$diff = $nowDt->diff($ageDt);
$age = $diff->y;
答案 1 :(得分:0)
您需要单独检查两种组合。检查:
OR
示例:
if (($DOBYear === '1999' && $DOBMonth === 'November') || ($DOBYear === '1999' && $DOBMonth === 'December'))
答案 2 :(得分:0)
试试这个:
// assumes you have a DOBday, otherwise drop this and the j
$dob = DateTime::createFromFormat(
'Y F j',
$DOBYear. ' ' . $DOBMonth . ' ' . $DOBday
);
$cutoff = new DateTime();
$cutoff->sub('P16Y'); // take off the 16 years.
if ($cutoff < $dob) {
echo 'You have to be at least 16 years to register';
}
答案 3 :(得分:0)
您需要更改if,尝试:
if ($DOBYear === '1999' && $DOBMonth === 'November' || $DOBYear === '1999' && $DOBMonth === 'December'){
echo('You have to be at least 16 years to register');
}
或
if ($DOBYear === '1999' && ($DOBMonth === 'November' || $DOBMonth === 'December')){
echo('You have to be at least 16 years to register');
}