php - 有什么区别? : and ||

标签 php

使用 ?: 条件运算符和 || 逻辑 OR 有什么区别。

我发现我的代码适用于:

$screenpixelratio = !empty($_COOKIE['screenpixelratio']) || $_COOKIE['screenpixelratio'] || $fallback_pixelratio;

但不是:

$screenpixelratio = !empty($_COOKIE['screenpixelratio']) ? $_COOKIE['screenpixelratio'] : $fallback_pixelratio;

有人可以解释一下为什么它适用于一个,但不能适用于另一个。

最佳答案

第一个 ( conditional or ) 是说...

this or this or this

另一个 ( ternary operation ) 在说

if this then this otherwise that

关于php - 有什么区别? : and ||,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14897901/

相关文章:

javascript - 我如何验证复选框?

php - 在我的帐户中添加个人资料图片(文件上传)> 在 WooCommerce 中编辑帐户

php - 如何为我的站点设置内容分发网络?

php - 从数据库中获取最接近今天的日期

php - 分解数据库值,然后通过选择 <select multiple> 标签来回显

javascript - 向 javascript 文件写入一行

php - 按特定键对数组进行排序

php - 从 PHP 启动 shell 命令

php - 取名为数组键名的变量

php - 使用 JS 复制表单并更改名称数据