php 语句 $is_index >= 0 && $where .= " AND is_index=" .$is_index; $is_index >= 0 && $where .= " AND is_index=" .$is_index;前面判断是否是大于等于零,关键是中间加了&&与逻辑符,这个就有点弄不懂了
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/01 03:34:34
![php 语句 $is_index >= 0 && $where .=](/uploads/image/z/15158869-61-9.jpg?t=php+%E8%AF%AD%E5%8F%A5+%24is_index+%3E%3D+0+%26%26+%24where+.%3D+%22+AND+is_index%3D%22+.%24is_index%3B+%24is_index+%3E%3D+0+%26%26+%24where+.%3D+%22+AND+is_index%3D%22+.%24is_index%3B%E5%89%8D%E9%9D%A2%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E6%98%AF%E5%A4%A7%E4%BA%8E%E7%AD%89%E4%BA%8E%E9%9B%B6%2C%E5%85%B3%E9%94%AE%E6%98%AF%E4%B8%AD%E9%97%B4%E5%8A%A0%E4%BA%86%26%26%E4%B8%8E%E9%80%BB%E8%BE%91%E7%AC%A6%2C%E8%BF%99%E4%B8%AA%E5%B0%B1%E6%9C%89%E7%82%B9%E5%BC%84%E4%B8%8D%E6%87%82%E4%BA%86)
php 语句 $is_index >= 0 && $where .= " AND is_index=" .$is_index; $is_index >= 0 && $where .= " AND is_index=" .$is_index;前面判断是否是大于等于零,关键是中间加了&&与逻辑符,这个就有点弄不懂了
php 语句 $is_index >= 0 && $where .= " AND is_index=" .$is_index;
$is_index >= 0 && $where .= " AND is_index=" .$is_index;
前面判断是否是大于等于零,关键是中间加了&&与逻辑符,这个就有点弄不懂了
php 语句 $is_index >= 0 && $where .= " AND is_index=" .$is_index; $is_index >= 0 && $where .= " AND is_index=" .$is_index;前面判断是否是大于等于零,关键是中间加了&&与逻辑符,这个就有点弄不懂了
这个是一个技巧.
对于||操作,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;