参考指南:这个符号在PHP中是什么意思? (PHP 语法)

2024-05-25

这是什么?

这是关于 PHP 语法时不时出现的问题的集合。这也是一个社区 Wiki,因此邀请每个人参与维护此列表。

为什么是这样?

过去很难找到有关运算符和其他语法标记的问题。
主要思想是提供 Stack Overflow 上现有问题的链接,这样我们就可以更轻松地引用它们,而不是复制 PHP 手册中的内容。

注:自 2013 年 1 月起,Stack Overflow是否支持特殊字符 https://meta.stackexchange.com/questions/160100/a-new-search-engine-for-stack-exchange。只需用引号将搜索词括起来,例如[php] "==" vs "===" https://stackoverflow.com/search?q=%5Bphp%5D%20%22===%22%20vs%20%22==%22

我应该在这里做什么?

如果您因为问了这样的问题而被某人指向这里,请查找下面的特定语法。链接到的页面PHP手册 http://php.net/manual/en/index.php连同链接的问题可能会回答您的问题。如果是这样,我们鼓励您对答案进行投票。此列表并不意味着可以替代其他人提供的帮助。

The List

如果您的特定令牌未在下面列出,您可能会在解析器令牌列表 http://secure.php.net/manual/en/tokens.php.


& 按位运算符 http://secure.php.net/manual/en/language.operators.bitwise.php or 参考 http://secure.php.net/manual/en/language.references.php

  • 什么时候应该使用按位运算符? https://stackoverflow.com/questions/4705838
  • 是否需要在对象前面使用&符号? https://stackoverflow.com/questions/21058439(&$)

=& 参考 http://secure.php.net/manual/en/language.references.php


&= 按位运算符 http://secure.php.net/manual/en/language.operators.bitwise.php


&& 逻辑运算符 http://secure.php.net/manual/en/language.operators.logical.php

  • PHP - 和/或关键字 https://stackoverflow.com/questions/4502092

% 算术运算符 http://secure.php.net/manual/en/language.operators.arithmetic.php

  • PHP 中的百分号是什么意思? https://stackoverflow.com/questions/1934173
  • 什么是 PHP 运算符 % 以及如何在实际示例中使用它? https://stackoverflow.com/questions/3204919

!! 逻辑运算符 http://secure.php.net/manual/en/language.operators.logical.php

  • PHP 中的双非 (!!) 运算符 https://stackoverflow.com/questions/2127260

@ 错误控制运算符 http://secure.php.net/manual/en/language.operators.errorcontrol.php

  • PHP中的@符号有什么用? https://stackoverflow.com/questions/1032161
  • PHP 中变量名前的“At”符号:@$_POST https://stackoverflow.com/questions/3551527
  • PHP 函数和@functions https://stackoverflow.com/questions/3984864
  • 我应该在 PHP 代码中使用 @ 吗? https://stackoverflow.com/questions/4872340
  • @在PHP中是什么意思? https://stackoverflow.com/questions/3621215

?: 三元运算符 http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary

  • PHP 运算符“?”是什么?和“:”调用,它们做什么? https://stackoverflow.com/questions/1080247
  • PHP 中的 ?: 运算符(“Elvis 运算符”) https://stackoverflow.com/questions/1993409
  • 在哪里可以阅读有关用“?”完成的条件的信息。和“:”(冒号)? https://stackoverflow.com/questions/4055355
  • 使用 PHP 5.3 ?: 运算符 https://stackoverflow.com/questions/4210187

双问号

?? 空合并运算符 https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op(自 PHP 7 起)

  • PHP 中 C# 的空合并运算符 (??) https://stackoverflow.com/questions/7278835

问号后跟类型声明

?string ?int ?array ?bool ?float 可空类型声明 https://www.php.net/manual/en/migration71.new-features.php(自 PHP 7.1 起)

  • 如何使用可空类型 https://stackoverflow.com/a/48450841
  • 可空返回类型声明 https://stackoverflow.com/a/54217328/250259

?->问号后跟对象运算符是空安全运算符 https://stackoverflow.com/a/62178856/250259(自 PHP 8.0 起)

  • PHP 中有“nullsafe 运算符”吗? https://stackoverflow.com/questions/12351737/is-there-a-nullsafe-operator-in-php

: 控制结构的替代语法 http://secure.php.net/manual/en/control-structures.alternative-syntax.php, 三元运算符 http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary, 返回类型声明 https://www.php.net/manual/en/language.types.declarations.php

  • PHP 中的“:”是什么? https://stackoverflow.com/questions/2908095
  • PHP 中的“:”是什么意思? https://stackoverflow.com/questions/4747761
  • 方法声明后的冒号? https://stackoverflow.com/questions/40346754

:: 范围解析运算符 http://secure.php.net/manual/en/language.oop5.paamayim-nekudotayim.php

  • PHP 中两个冒号是什么意思? https://stackoverflow.com/questions/2903564
  • PHP 令牌名称 T_PAAMAYIM_NEKUDOTAYIM 的含义是什么? https://stackoverflow.com/questions/2588298
  • PHP 中 ::(双冒号)和 ->(箭头)有什么区别? https://stackoverflow.com/questions/3173501
  • PHP 中的后期静态绑定到底是什么? https://stackoverflow.com/questions/1912902
  • 静态::静态函数名() https://stackoverflow.com/questions/4120755
  • 意外的 T_PAAMAYIM_NEKUDOTAYIM,需要 T_NS_Separator https://stackoverflow.com/questions/8734823

\ 命名空间 http://php.net/namespaces

  • PHP 中的反斜杠——它是什么意思? https://stackoverflow.com/questions/10788400
  • \(反斜杠)在 PHP (5.3+) 中起什么作用? https://stackoverflow.com/questions/4790020

-> 类和对象 http://secure.php.net/manual/en/language.oop5.php

  • PHP 运算符“->”叫什么? https://stackoverflow.com/questions/2588149
  • PHP 中什么地方使用对象运算符“->”? https://stackoverflow.com/questions/3037526
  • PHP 中 ::(双冒号)和 ->(箭头)有什么区别? https://stackoverflow.com/questions/3173501
  • PHP 语法 $var1->$var2 是什么意思? https://stackoverflow.com/questions/2316370
  • PHP 中的“->”是什么意思? https://stackoverflow.com/questions/4502587

=> Arrays http://secure.php.net/manual/en/language.types.array.php

  • PHP 中的“=>”是什么意思? https://stackoverflow.com/questions/1241819
  • PHP 中 => 的使用 https://stackoverflow.com/questions/1655336
  • foreach($ex as $k=>$v) 中的 $k => $v 是什么意思? https://stackoverflow.com/questions/4758791

^ 按位运算符 http://secure.php.net/manual/en/language.operators.bitwise.php

  • 按位运算符 XOR ('^') 如何工作? https://stackoverflow.com/questions/2674920
  • PHP 中的 ^ 是什么意思? https://stackoverflow.com/questions/2724936

>> 按位运算符 http://secure.php.net/manual/en/language.operators.bitwise.php

  • >> 在 PHP 中是什么意思? https://stackoverflow.com/questions/2790329

<< 按位运算符 http://secure.php.net/manual/en/language.operators.bitwise.php

  • PHP 中奇怪的打印行为? https://stackoverflow.com/questions/9718689/strange-print-behaviour-in-php

<<< 赫里多克和现在多克 http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

  • PHP中 https://stackoverflow.com/questions/5539669
  • PHP 表达式 https://stackoverflow.com/questions/1048481
  • PHP中“ https://stackoverflow.com/questions/3700042
  • 在 PHP 中使用 https://stackoverflow.com/questions/2090081
  • PHP 中的这种语法是什么? https://stackoverflow.com/questions/2333779

= 赋值运算符 http://secure.php.net/manual/en/language.operators.assignment.php

  • 3个不同的等于 https://stackoverflow.com/questions/2063480

== 比较运算符 http://secure.php.net/manual/en/language.operators.comparison.php

  • PHP 相等(== 双等于)和恒等(=== 三等)比较运算符有何不同? https://stackoverflow.com/questions/80646
  • PHP != 和 == 运算符 https://stackoverflow.com/questions/1663451
  • 3个不同的等于 https://stackoverflow.com/questions/2063480
  • PHP 中的类型杂耍和(严格)大于/小于比较 https://stackoverflow.com/questions/15813490/

=== 比较运算符 http://secure.php.net/manual/en/language.operators.comparison.php

  • “= =”是什么意思? https://stackoverflow.com/questions/1117967
  • PHP 相等(== 双等于)和恒等(=== 三等)比较运算符有何不同? https://stackoverflow.com/questions/80646
  • 3个不同的等于 https://stackoverflow.com/questions/2063480
  • PHP 中的类型杂耍和(严格)大于/小于比较 https://stackoverflow.com/questions/15813490/

!== 比较运算符 http://secure.php.net/manual/en/language.operators.comparison.php

  • PHP 中的 !== 比较运算符是什么意思? https://stackoverflow.com/questions/1298083
  • PHP 中的 !== 和 != 有区别吗? https://stackoverflow.com/questions/1139154

!= 比较运算符 http://secure.php.net/manual/en/language.operators.comparison.php

  • PHP != 和 == 运算符 https://stackoverflow.com/questions/1663451
  • PHP 中的 !== 和 != 有区别吗? https://stackoverflow.com/questions/1139154
  • 比较,!== 与 != https://stackoverflow.com/questions/6356826
  • 和 != 有什么区别 https://stackoverflow.com/questions/9671785/what-is-the-difference-between-and

<> 比较运算符 http://secure.php.net/manual/en/language.operators.comparison.php

  • PHP 运算符 https://stackoverflow.com/questions/249312
  • https://stackoverflow.com/questions/589391 https://stackoverflow.com/questions/589391
  • 和 != 有什么区别 https://stackoverflow.com/questions/9671785
  • PHP 中的类型杂耍和(严格)大于/小于比较 https://stackoverflow.com/questions/15813490/

<=> 比较运算符 http://secure.php.net/manual/en/language.operators.comparison.php(自 PHP 7.0 起)

  • 宇宙飞船(三路比较)算子 https://stackoverflow.com/a/31298778

| 按位运算符 http://secure.php.net/manual/en/language.operators.bitwise.php

  • | 之间有什么区别?和||运营商? https://stackoverflow.com/questions/2233835
  • 使用单个管道“|”有什么作用在函数参数中做什么? https://stackoverflow.com/questions/13811922

|| 逻辑运算符 http://secure.php.net/manual/en/language.operators.logical.php

  • | 之间有什么区别?和||运营商? https://stackoverflow.com/questions/2233835
  • PHP - 和/或关键字 https://stackoverflow.com/questions/4502092
  • || 到底是什么?意思是? https://stackoverflow.com/questions/5666741
  • PHP 中 or 运算符的行为 https://stackoverflow.com/questions/12213283

~ 按位运算符 http://secure.php.net/manual/en/language.operators.bitwise.php

  • 这个 ~ 运算符在这里意味着什么? https://stackoverflow.com/questions/1967360

+ 算术运算符 http://secure.php.net/manual/en/language.operators.arithmetic.php, 数组运算符 http://secure.php.net/manual/en/language.operators.array.php

  • 使用“+”(数组联合运算符)合并两个数组是如何工作的? https://stackoverflow.com/questions/2140090

+= and -= 赋值运算符 http://secure.php.net/manual/en/language.operators.assignment.php

  • += 是做什么用的? https://stackoverflow.com/questions/542995
  • 我的 PHP 文档中的 `$page -= 1` 是什么意思? https://stackoverflow.com/questions/7140158

++ and -- 自增/自减运算符 http://secure.php.net/manual/en/language.operators.increment.php

  • 了解增量 https://stackoverflow.com/questions/1968371
  • 回答如下 https://stackoverflow.com/a/3737177

.= 赋值运算符 http://secure.php.net/manual/en/language.operators.assignment.php

  • PHP 中 .= 和 += 有什么区别? https://stackoverflow.com/questions/2202331
  • PHP 中的 .=(点等于)运算符是什么? https://stackoverflow.com/questions/1241432

. 字符串运算符 http://secure.php.net/manual/en/language.operators.string.php

  • 与 echo 和 return 连接时句号和逗号之间的区别? https://stackoverflow.com/questions/1466408
  • a 是什么意思? (点)在 PHP 中做什么? https://stackoverflow.com/questions/6484968

, 函数参数 http://php.net/manual/en/functions.arguments.php

  • 与 echo 和 return 连接时句号和逗号之间的区别? https://stackoverflow.com/questions/1466408

, 变量声明 http://php.net/manual/en/language.variables.scope.php

  • 变量声明中的逗号是什么意思? https://stackoverflow.com/questions/41383218

$$ 变量变量 http://php.net/manual/en/language.variables.variable.php

  • PHP 中的 $$(美元或双美元)是什么意思? https://stackoverflow.com/questions/2715654
  • PHP 中的“$$”是什么 https://stackoverflow.com/questions/4169882
  • $函数()和$$变量 https://stackoverflow.com/questions/4891872

` 执行操作符 http://php.net/manual/en/language.operators.execution.php

  • 反引号``叫什么? https://stackoverflow.com/questions/6002296

<?= 短开标签 http://php.net/manual/en/ini.core.php#ini.short-open-tag

  • PHP中这个符号是什么意思 = https://stackoverflow.com/questions/1963901
  • PHP 中“=”是什么意思? https://stackoverflow.com/questions/2020445
  • = 是什么意思? https://stackoverflow.com/questions/1959256/what-does-mean

[] Arrays http://secure.php.net/manual/en/language.types.array.php(自 PHP 5.4 起的短语法)

  • PHP 数组...空括号的含义是什么? https://stackoverflow.com/q/20709055/2758197
  • 是什么意思 [] https://stackoverflow.com/questions/6933345
  • PHP array_push() 与 myArray[] https://stackoverflow.com/questions/2431629
  • 从 PHP 数组读取时 [] 是什么意思? https://stackoverflow.com/questions/3908576
  • 数组的简写:文字$var = []空数组 https://stackoverflow.com/questions/4271874

<? 开始和结束标签 http://secure.php.net/manual/en/language.basic-syntax.php

  • PHP 短标签可以使用吗? https://stackoverflow.com/questions/200640

..双点字符范围

  • 允许双点范围语法的本机 PHP 函数 https://stackoverflow.com/q/72865138/2943403

... 参数解包 http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list(自 PHP 5.6 起)


** 求幂 http://secure.php.net/manual/en/migration56.new-features.php#migration56.new-features.exponentiation(自 PHP 5.6 起)


# 一行 shell 风格的注释 http://php.net/manual/en/language.basic-syntax.comments.php

  • 我可以在 PHP 中使用哈希值进行注释吗? https://stackoverflow.com/questions/9093609/can-i-use-hashes-for-comments-in-php

#[] 属性 https://stackoverflow.com/a/71641821/6660678(自 PHP 8 起)



自增/自减运算符 http://php.net/manual/en/language.operators.increment.php

++增量运算符

--自减运算符

Example    Name              Effect
---------------------------------------------------------------------
++$a       Pre-increment     Increments $a by one, then returns $a.
$a++       Post-increment    Returns $a, then increments $a by one.
--$a       Pre-decrement     Decrements $a by one, then returns $a.
$a--       Post-decrement    Returns $a, then decrements $a by one.

它们可以位于变量之前或之后。

如果放在变量之前,则对变量进行递增/递减操作first然后返回结果。如果放在变量后面,则变量是first返回,则递增/递减操作完成。

例如:

$apples = 10;
for ($i = 0; $i < 10; ++$i) {
    echo 'I have ' . $apples-- . " apples. I just ate one.\n";
}

实例 http://codepad.org/5ZD3j0xb

在上述情况下++$i使用,因为它更快。$i++会得到相同的结果。

预递增要快一点,因为它确实递增变量,然后“返回”结果。后递增创建一个特殊变量,将第一个变量的值复制到其中,并且仅在使用第一个变量后,才将其值替换为第二个变量的值。

但是,您必须使用$apples--,从一开始,您想要显示当前苹果的数量,并且then你想从中减去一。

您还可以在 PHP 中增加字母:

$i = "a";
while ($i < "c") {
    echo $i++;
}

Once z到达了aa是下一个,依此类推。

请注意,字符变量可以递增,但不能递减,即使如此,也仅支持纯 ASCII 字符(a-z 和 A-Z)。


堆栈溢出帖子:

  • 了解增量 https://stackoverflow.com/questions/1968371/understanding-incrementing
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

参考指南:这个符号在PHP中是什么意思? (PHP 语法) 的相关文章

  • 如何从父类中获取子类名

    我试图在不需要子类上的函数的情况下完成此任务 这可能吗 我有一种感觉 但我真的很想确定
  • 为什么我的会话仍然存在?

    我一定很愚蠢 因为似乎一件相当明显的事情现在让我完全困惑 我有一个会议 ie SESSION handbag id 在某个时刻 我需要彻底终止这个会话 ie at the start of the page session start el
  • php 数组中出现意外的 json 输出结构

    我正在尝试转换动态数据 如何从 PHP 获取此 JSON JSON 122240cb 253c 4046 adcd ae81266709a6 item 0 3 这就是我所做的 但它不起作用 PHP json array 122240cb 2
  • 一种无需 JavaScript 即可在 PHP 中确定浏览器宽度的方法?

    首先有吗 或者我必须使用javascript 我希望能够更改使用的 CSS 因此 frex 我可以为移动设备或其他设备加载较小的字体 不幸的是 仅使用 PHP 无法检测用户分辨率 如果您使用 Javascript 则可以在 cookie 中
  • setcookie with expire=0 浏览器关闭后不会过期

    我使用setcookie来制作一个过期 0的cookie 从 PHP 文档来看 link http php net manual en function setcookie php cookie 过期的时间 这是一个 Unix 时间戳 所以
  • PHP 通过 SSL 连接到 MS SQL

    我想要实现的目标非常简单 我想通过安全连接从 PHP 脚本连接到外部 MS SQL 数据库 然而 这已被证明是有问题的 到目前为止 经过三个小时的研究 我不知所措 客户端的平台是Ubuntu 这意味着我无法使用SQLSRV 安全连接已经在不
  • 无法访问 localhost/xampp/index.php

    我刚刚安装了 Windows 7 的 XAMPP 控制面板似乎工作正常 我启动了 MySql 和 Apache 我遇到的问题是 当我在浏览器 Google Chrome 中输入 localhost 时 它会将我发送到 http localh
  • Yii2 - 错误请求 (#400) |前端和后端cookie

    仅当我打开时才会出现此问题frontend and backend在相同的browser 设想 与后端交互 gt 切换选项卡 gt 与前端交互 gt 切换选项卡返回 gt 与后端交互 gt 错误请求 400 Cookie 后端 identi
  • CakePHP 视图包括其他视图

    我有一个 CakePHP 应用程序 在某些时候会显示带有产品媒体 图片或视频 的视图 我想知道是否有某种方式可以包含另一个威胁视频或威胁图片的视图 具体取决于标志 我想将这些 小视图 用于其他几个目的 所以它应该 像 蛋糕组件一样 以便重用
  • 如何从网站网址中隐藏 .html 扩展名

    我知道这个问题以前曾被问过 但有人知道隐藏 html 扩展名的好方法吗 我已经尝试了许多代码和许多答案https stackoverflow com https stackoverflow com 但我没有看到结果 那是我再问你一次 我有一
  • 如何在 PHP 的 HTML 页面中显示错误消息?

    我有以下登录表单 login php 其中要求输入用户名和密码
  • PDO PHP 连接,致命错误

    我的连接类 firstcode php class DB functions public db function construct try db new PDO mysql localhost dbname xxx charset ut
  • 分页显示所有其他页面上第 1 页的相同帖子

    我最近在创建即将发生的事件列表时得到了很多帮助 请参阅此处显示即将举行的活动 包括今天的活动 https stackoverflow com questions 17343615 showing upcoming events includ
  • 覆盖 FOS 用户包中的“更改密码”模板

    我做了一些研究 遗憾的是找不到任何帮助 因此 我将 FOSUserBundle ChangePasswordAction 渲染到我的模板中 但它显示供应商提供的默认模板 我的渲染控制器的模板 block body h2 Einstellun
  • Laravel Vue 组件只能传递数字?

    在我的 UserMenu vue 中我写道 export default props nameVal data return 并在blade php中
  • 使用 PHP 从 Mongo 解码 JSON

    我已经看过这个线程 PHP 解码嵌套 JSON https stackoverflow com questions 3555335 php decode nested json并没有设法用它来解决我的问题 我目前正在从 Mongo 获取 J
  • 如何在codeigniter中将上传图片比例限制为16:9?

    这是我用来上传图像的代码 this gt load gt library upload ext pathinfo file name PATHINFO EXTENSION img name now ext imgConfig upload
  • PHP 表单 - 带验证蜜罐

    我有以下内容 效果很好 但对垃圾邮件机器人开放 我想放入蜜罐 而不是验证码 下面的代码适用于验证姓名 电子邮件 消息 但我无法让它与蜜罐一起工作 任何人都可以查看 蜜罐 代码并告诉我如何修复它吗 我希望表单给出 success2 不允许垃圾
  • PHP 拒绝从 var_dump、print 等输出数据

    我目前正在运行 WAMP 服务器 并且在过去的 30 分钟内一直在尝试弄清楚我的项目如何以及为什么不会输出任何指定的 PHP 数据 起初我以为是因为我有一个 htaccess文件的output buffering被禁用 所以我删除了它 仍然
  • 如何在 PHP 5.6 中通过 php.ini 设置“verify_peer_name=false”SSL 上下文选项

    案例 我想打开 SSL 连接localhost而 SSL 证书是 FQDN 的问题 问题 没有进行特殊处理就行 下面的程序失败并显示以下消息 PHP Warning stream socket enable crypto Peer cert

随机推荐