statement evaluate to true?

if ($opts['width'] == 'fs' || $opts['height'] == 'fs' || $opts['ratio'] == 'fs') {
    var_dump($opts); // result of this see bellow
}

Result of var_dump($opts) inside (!) if-statement:

array(3) {
   'width' => int(200)
   'height' => int(0)
   'ratio' => int(0)
}

How is this possible? None of the array's values is (stirng) fs?


Because 0 == 'fs' . See this conversion table .

PHP has the === operator to compare both value and type.

For a more extensive table: Type-juggling and (strict) greater/lesser-than comparisons in PHP

链接地址: http://www.djcxy.com/p/58516.html

上一篇: 字符串'w32'== 0在php中评估为true。 是吧?

下一篇: 声明评估为真?