这个if语句如何评估为true?

时间:2013-08-24 18:19:10

标签: php if-statement

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

var_dump($opts) 内的结果(!)if-statement:

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

这怎么可能?数组的值都不是(stirng)fs?

1 个答案:

答案 0 :(得分:3)

因为0 == 'fs'。请参阅 conversion table

PHP有===运算符来比较值类型。

更广泛的表:Type-juggling and (strict) greater/lesser-than comparisons in PHP

相关问题