if ("false" == 0) echo "true
";
// => true
PHP文件指出:
var_dump((bool) "false"); // bool(true)
如果是虫子,我在哪里可以归档?
if ("false" == 0) echo "true
";
// => true
PHP文件指出:
var_dump((bool) "false"); // bool(true)
如果是虫子,我在哪里可以归档?
不,不是虫子,不用麻烦了
这种似乎不一致的行为与“false”一词无关。 它与您的字符串有关, 您的字符串只由字母组成, 没有数字数字, 所以当它被投到一个整数来比较时( ), 它的结果为 0, 使得
0 =0 < =0 > =0
能够评估真实性 。
如果将任何其他字母字符串比作 0,结果会是一样的:
"abcd" == 0
"a" == 0
"true" == 0
它不是一个错误, 在比较不同数据类型值时, 它是一个有详细记录的特点 - 在本案中, 字符串为整数 。 PHP 将字符串转换为整数来进行比较, “ 假” 转换为 0 。
见"http://www.php.net/manual/en/language.operators.comparison.php" rel=“no follow”>手册:
If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically.
如果字符串以有效的数字数据开始,则此数值将是所使用的数值。 否则, 数值将为 0 (零) 。
为了避免这种行为,使用严格的打字方法比较:
if ("false" === 0) echo "true
";
问题是, PHP 除非使用严格的比较, 否则会投放变量。 正如其他人所提到的, 字符串 < code> “ false” 正在投放成整数 。
如果您想要做一个比较而不使用排版 :
"false" === 0
这或许有帮助:这些是PHP认为唯一虚假的东西:
尝试避免文本的字符串比较, 并粘贴到布林值!
I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...
<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...
I found this script online that creates a thumbnail out of a image but the thumbnail image is created with poor quality how can I improve the quality of the image. And is there a better way to create ...
如何确认来自正确来源的数字。
Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...
I wonder there is a way to post a message to a facebook business page with cURL? thanks
I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...
How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...