I guess the main reason for PHP to behave like this is to make life
easier for many everyday situations.
EXAMPLE:
User input via GET or POST - usually string
You compare it to some value - int/string or whatever
So if a user posts '17' (string) and you compare it to 17 (int),
unless you are
While PHP has a lot of nice features, it also has some traps which I am
forever falling
into. One which I find particularly hard to understand is how mixed mode
comparisons work.
For instance
$string = 'elephant';
If($string == 0) returns true;
If($string != 0) returns false;
Clancy wrote:
While PHP has a lot of nice features, it also has some traps which I
am forever falling into. One which I find particularly hard to
understand is how mixed mode comparisons work. For instance
$string = 'elephant';
If($string == 0) returns true;
If($string != 0) returns
Clancy schreef:
While PHP has a lot of nice features, it also has some traps which I am
forever falling
into. One which I find particularly hard to understand is how mixed mode
comparisons work.
For instance
$string = 'elephant';
If($string == 0) returns true;
If($string != 0)
Can anyone explain clearly why comparing a string
with zero gives this apparently anomalous result?
?php
$string = 'oleyphoont';
var_dump((int)$string, $string == 0, $string == 1);
?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Have you tried with a mouse?
--
Dotan Cohen
http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه-و-ي
А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
Jochem Maas wrote:
Clancy schreef:
While PHP has a lot of nice features, it also has some traps which I am forever falling
into. One which I find particularly hard to understand is how mixed mode comparisons work.
For instance
$string = 'elephant';
If($string == 0) returns
惠新宸 wrote:
Jochem Maas wrote:
Clancy schreef:
While PHP has a lot of nice features, it also has some traps which I am
forever falling
into. One which I find particularly hard to understand is how mixed mode
comparisons work.
For instance
$string = 'elephant';
If($string == 0)
On Thu, 2009-02-12 at 13:12 +0200, Dotan Cohen wrote:
Have you tried with a mouse?
Non-strings equate to a boolean value of 1 when they are converted to a
boolean value automatically (in the case of comparison queries) when
they contain a value. Strings of 0 length are converted to a 0. In
On Thu, 12 Feb 2009 23:47:31 +0800, huixinc...@baidu.com (???) wrote:
Jochem Maas wrote:
Clancy schreef:
While PHP has a lot of nice features, it also has some traps which I am
forever falling
into. One which I find particularly hard to understand is how mixed mode
comparisons work.
10 matches
Mail list logo