我的任务是能够以某人的生日作为论据,并以这种特定方式返回年龄以及是否生日
getBirthDate('09/06/1992'); // 返回数组('age' => 21, 'birthday' => true);
我无法让布尔值正常工作,因为即使 if 语句为真,它也总是返回 else 语句。
<?php
function getBirthDate($birthdate)
{
$today =getdate();
$day =array($today["mon"], $today["mday"]);
$newBday = str_replace("/",",",$birthdate);
$birthDate = explode(",",$newBday);
$monthDay = array($birthDate["0"],$birthDate[1]);
$compared = array_diff($day,$monthDay);
if ($compared == ""){
$age = ($today["year"]-$birthDate["2"]);
$dateArray = array( "age" => "$age", "birthday" => "True");
return print_r ($dateArray);
return True;
}
else{
if ($monthDay[0] < $day[0]){
$age = (($today["year"]-$birthDate["2"])-1);
$dateArray = array( "age" => "$age", "birthday" => "False");
return print_r($dataArray);
return True;
}
else{
$age = (($today["year"]-$birthDate["2"]));
$dateArray = array( "age" => "$age", "birthday" => "False");
return print_r($dateArray);
return True;
}
}
}
getBirthDate("9/6/1993")
?>