php 语句 $is_index >= 0 && $where .= " AND is_index=" .$is_ind

php 语句 $is_index >= 0 && $where .= " AND is_index=" .$is_index;
$is_index >= 0 && $where .= " AND is_index=" .$is_index;
前面判断是否是大于等于零,关键是中间加了&&与逻辑符,这个就有点弄不懂了
印象天 1年前 已收到1个回答 举报

天使也会哭 幼苗

共回答了10个问题采纳率:90% 举报

这个是一个技巧.
对于||操作,php按照顺序判断,当发现了真值后就不再进行其他的判断,如 1 || (echo 'test'),echo 'test'是不会执行的,因为第一个表达式是1,后面就不用再判断了,而 0 || (echo 'test')则会看到test的输出
同理,对于&&操作符,当php发现一个值为假时,就不再继续判断了,因此当$is_index为0时 $is_index >=0 && $where.=' and ...'中 后面的$where赋值不会被执行,反之 则会为$where赋值
问题中的代码等效于
if ($is_index >= 0) $where .= "AND is_index = " .$is_index;

1年前

8
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.042 s. - webmaster@yulucn.com