Re: how can one variable equal 2 things??
- From: Michael Winter <m.winter@xxxxxxxxxxxxxxxx>
- Date: Sat, 02 Jul 2005 22:52:56 GMT
On 02/07/2005 23:34, Marcus wrote:
[snip]
if anything, I would have thought testing if ['default'] == 1 would be a boolean true since the variable exists and is not NULL, but testing if ['default'] == 1 returns FALSE.
This is due to implicit type conversion. When you use the equality (==) rather than strict equality (===) and compare two different types, the values are converted into something that can be compared in some meaningful way.
If you compare a string to a number, an attempt is made to convert that string to a number first. If the string starts with valid number data, then that will be the used value, otherwise the comparison will be against zero (0).
The string 'default' doesn't have anything resembling a number at its start, so it will be converted to zero. You then perform a comparison against literal zero, hence the expression evaluates to true.
See the type comparison page[1], as well as the section on converting strings to numbers[2], in the manual.
Mike
[1] <URL:http://www.php.net/manual/en/types.comparisons.php>
[2] <URL:http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion>
-- Michael Winter Prefix subject with [News] before replying by e-mail. .
- Follow-Ups:
- Re: how can one variable equal 2 things??
- From: Marcus
- Re: how can one variable equal 2 things??
- References:
- how can one variable equal 2 things??
- From: Marcus
- how can one variable equal 2 things??
- Prev by Date: Re-draw a form with user's input.
- Next by Date: Re: A starnge questin
- Previous by thread: Re: how can one variable equal 2 things??
- Next by thread: Re: how can one variable equal 2 things??
- Index(es):
Relevant Pages
|