Re: Odd Code Error.
| From: | Robert Cummings | Date: | Wed, 21 Jan 2004 03:52:50 +0000 |
| Subject: | Re: Odd Code Error. | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-175264@lists.php.net to get a copy of this message | ||
On Tue, 2004-01-20 at 22:39, Luke wrote:
> yeah its strange,
>
> $test is equal to $test2,
> $test is equal to $test3
> but $test2 is not equal to $test3,
>
> $test = "string";
> $test2 = true;
> $test3 = 0;
> if($test == $test2){
> echo "hi";
> }
>
Looks fine to me...
$test == $test2: $test is not an empty string and thus evaluates to
true.
$test == $test3: $test is converted to an integer to compare against
$test3. Conversion of $test to integer results in 0,
which happens to be equal to $test3
You should read the section on type juggling.
http://ca2.php.net/language.types.type-juggling
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com
|
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'