【问题标题】:PHP - Why does || return 1 while OR returns value? [duplicate]PHP - 为什么 ||返回 1 而 OR 返回值? [复制]
【发布时间】:2018-02-24 00:35:22
【问题描述】:

我正在从我的客户端向服务器发送一个 POST 请求,并像这样在服务器上获取值:

$fileName = filter_input(INPUT_POST, "fileName", FILTER_SANITIZE_FULL_SPECIAL_CHARS) or exit("No Filename");
exit($fileName);

示例输出: 'vacation_photo.jpg'

这很好用,但是,如果我将 or 替换为 ||,那么我会得到 1 作为输出。

输出: '1'

我正在阅读this article,但我仍然不明白。

【问题讨论】:

标签: php


【解决方案1】:

||or 具有不同的优先级。见operator precedence。如果用括号说清楚,你会得到:

fileName = (filter || exit)
(fileName = filter) OR exit

然后第二行中的出口打印为 1。

【讨论】:

    猜你喜欢
    • 2019-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-16
    • 2014-07-03
    • 2014-12-29
    • 1970-01-01
    相关资源
    最近更新 更多