我有一個函數,它是將用戶的出生日期發送到數據庫的類或庫的一部分。出於某種原因,保存該信息($this->birthdate)
的變量發送的值爲0000-00-00,而不是實際的出生日期。在函數中分配日期後,PHP變量的值爲0
這裏是我的示例代碼:
function isAgeValid(){
$birthDate1=$this->birth_year.'-'.$this->birth_month.'-'.$this->birth_day;
$birthDate1 = explode("-", $birthDate1);
$age = (date("md", date("U", mktime(0, 0, 0, $birthDate1[0], $birthDate1[1], $birthDate1[2]))) > date("md")
? ((date("Y")-$birthDate1[2])-1):(date("Y")-$birthDate1[2]));
$this->birthdate=($birthDate1);
return ($age > 17);
}
不要以爲你的代碼是正確的,永遠的var_dump()的結果,以確認你的輸出。 –