这是我的代码:
$curr_year = date('Y'); $dob_year = rand($curr_year-18,$curr_year-47); $dob_month = rand(01,12); $dob_day = rand(01,30); echo $dob = $dob_month.'/'.$dob_day.'/'.$dob_year;
我的结果是1/2/1988,但我的要求是结果应该是01/02/1988
使用
str_pad
.
echo $dob = str_pad($dob_month,2,'0',STR_PAD_LEFT) . '/' . str_pad($dob_day,STR_PAD_LEFT) . '/'.$dob_year;