in a book i am ready now : O'Reilly - Web Database Application with PHP
and MySQL, 2nd ed. by David Lane, Hugh E. Williams
on chapter 9 the author give an example for age validation :
(simplified code, not a direct quote)
$dob = mktime(0,0,0, 5, 3, 1983);
if ((float)$dob > (float)strtotim e("-18years"))
{
print "....";
return false;
}
my question is why the type casting to float ?
after all the return type of both mktime & strtotime is int, why the
need to cast to float?
the authors emphasize this in the explanation section by "We use the
mktime() function to convert the date of birth to a large numeric Unix
timestamp value, and the strtotime() function to discover the timestamp
of exactly 18 ago. *Both are cast to a large floating number to ensure
reliable comparison...*"
thank you for comment's ohh & yes - hope I'm not breaking any copyright
lows :).
and MySQL, 2nd ed. by David Lane, Hugh E. Williams
on chapter 9 the author give an example for age validation :
(simplified code, not a direct quote)
$dob = mktime(0,0,0, 5, 3, 1983);
if ((float)$dob > (float)strtotim e("-18years"))
{
print "....";
return false;
}
my question is why the type casting to float ?
after all the return type of both mktime & strtotime is int, why the
need to cast to float?
the authors emphasize this in the explanation section by "We use the
mktime() function to convert the date of birth to a large numeric Unix
timestamp value, and the strtotime() function to discover the timestamp
of exactly 18 ago. *Both are cast to a large floating number to ensure
reliable comparison...*"
thank you for comment's ohh & yes - hope I'm not breaking any copyright
lows :).
Comment