2008/5/28 C.R.Vegelin <[EMAIL PROTECTED]>:

> $var1 = "01011090"; $var2 = "010190"; // 2 strings
> if ($var1 < $var2) ECHO "var1 < var2"; else ECHO "var1 >= var2"; echo "<br 
> />";
> $r = strcmp ( $var1 , $var2 );
> if ($r < 0) ECHO "var1 < var2", "<br />";
>
> 2nd line says: $var1 >= $var2
> 4th line says: $var1 < $var2

Implicit type conversion. "<" is a numeric operator, so your strings
are silently promoted to integers, where (1011090 > 10190).

strcmp() treats the strings as strings, and orders them in something
close to ASCII order (which isn't the same as alphabetical ordering,
BTW, and see the comments at www.php.net/strcmp for locale-specific
gotchas).

PHP's implicit conversions can bite you if you don't understand them.
Try this one:

$a = 'string';
$b = 0;
if ($a==true && $b==false && $a==$b)
{
    echo ('universe broken');
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to