RE: [PHP] function question
| From: | John W. Holmes | Date: | Thu, 01 May 2003 13:24:46 +0000 |
| Subject: | RE: [PHP] function question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145947@lists.php.net to get a copy of this message | ||
> I am using a function mofied from an earlier post to check whether a
given
> date is valid and does not occur in the past, however when i try to
use
> the
> function with:
>
> if(futureDate($_POST[booking_date]) == 'weekend'){
> echo 'date is a weekend'
> }
>
> and the function is returning zero, it still enters the loop and
prints
> 'date is a weekend'
>
> I would be grateful for your help as this doesn't make sense to me!
>
> Date checking function:
>
> function futureDate($timestamp){
> $error = 0;
Type juggling. Since the function is returning an integer, PHP is going
to convert 'weekend' to an integer and compare them. A string like
'weekend' will be converted to zero, so the two will end up matching.
Have your function return an empty string as the default error.
$error = '';
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/