We use cookies.This website uses essential cookies to operate core features. With your consent, we also use analytics cookies to understand traffic and improve the service. For more details, see our .
If this tool helped you, you can buy us a coffee ☕
Quickly check PHP operator precedence and associativity with this free online programming tool.
cloneObject CreationNon-associative对对象执行浅拷贝,返回新的对象实例。
$copy = clone $obj;newObject CreationNon-associative调用类的构造方法创建一个新对象。
$user = new User();**ExponentiationRight-associative返回左操作数的右操作数次幂,右结合。
2 ** 10+exprUnary & Type CastingRight-associative返回操作数的数值并触发类型转换。
+ $x-exprUnary & Type CastingRight-associative返回操作数的相反数。
- $x++exprUnary & Type CastingRight-associative先将变量加 1,再返回新值。
++$i--exprUnary & Type CastingRight-associative先将变量减 1,再返回新值。
--$iexpr++Unary & Type CastingRight-associative返回当前值后将变量加 1。
$i++expr--Unary & Type CastingRight-associative返回当前值后将变量减 1。
$i--~Unary & Type CastingRight-associative对整数按位取反。
~ $mask(int)Unary & Type CastingRight-associative将表达式强制转换为整数类型。
(int) "42"(float)Unary & Type CastingRight-associative将表达式强制转换为浮点数类型。
(float) "3.14"(string)Unary & Type CastingRight-associative将表达式强制转换为字符串类型。
(string) 123(array)Unary & Type CastingRight-associative将表达式强制转换为数组类型。
(array) $obj(object)Unary & Type CastingRight-associative将表达式强制转换为对象类型。
(object) ['a' => 1](bool)Unary & Type CastingRight-associative将表达式强制转换为布尔类型。
(bool) $value@Unary & Type CastingRight-associative抑制表达式产生的错误信息(不影响 Fatal Error)。
@file_get_contents('x')instanceofType CheckingNon-associative判断对象是否为指定类、接口或其子类的实例。
$obj instanceof User!Logical NOTRight-associative对布尔值取反,true 变 false。
!$ready*MultiplicativeLeft-associative两个操作数相乘。
$a * $b/MultiplicativeLeft-associative两个数相除,整数除非整除时结果为浮点数。
10 / 3%MultiplicativeLeft-associative返回相除的余数。
10 % 3+AdditiveLeft-associative数值相加;对数组则保留左侧键执行合并。
$a + $b-AdditiveLeft-associative两个数相减。
$a - $b.String ConcatenationLeft-associativePHP 8 起优先级低于 + 和 - ,用于拼接字符串。
"Hi " . $name<<Bitwise ShiftLeft-associative整数按位左移指定位数。
1 << 3>>Bitwise ShiftLeft-associative整数按位右移指定位数。
16 >> 2<RelationalNon-associative左小于右返回 true。
$a < $b<=RelationalNon-associative左小于或等于右返回 true。
$a <= $b>RelationalNon-associative左大于右返回 true。
$a > $b>=RelationalNon-associative左大于或等于右返回 true。
$a >= $b==EqualityNon-associative进行类型转换后判断是否相等。
0 == '0'!=EqualityNon-associative等价于 <>,类型转换后判断不相等。
$a != $b===EqualityNon-associative类型与值都相等才返回 true。
0 === 0!==EqualityNon-associative类型不同或值不同时返回 true。
$a !== $b<>EqualityNon-associative等价于 !=,类型转换后判断不相等。
$a <> $b<=>EqualityNon-associativePHP 7+ 三向比较:左小返回 -1,相等返回 0,左大返回 1。
$a <=> $b&BitwiseLeft-associative整数按位与;变量前用作引用赋值。
$a & $b^BitwiseLeft-associative对整数按位执行异或运算。
$a ^ $b|BitwiseLeft-associative对整数按位执行或运算。
$a | $b&&Short-circuiting LogicLeft-associative短路求值:左侧为 false 时不计算右侧。
$a && $b||Short-circuiting LogicLeft-associative短路求值:左侧为 true 时不计算右侧。
$a || $b??Null CoalescingRight-associative左侧为 null 或未定义时返回右侧值,否则返回左侧。
$name ?? '匿名'? :Ternary ConditionalNon-associative条件为 true 返回中间值,否则返回最后值(PHP 8 起非结合)。
$x > 0 ? 1 : -1=AssignmentRight-associative将右侧的值赋给左侧变量。
$x = 10+=AssignmentRight-associative$x = $x + $y 的简写。
$x += 1-=AssignmentRight-associative$x = $x - $y 的简写。
$x -= 1*=AssignmentRight-associative$x = $x * $y 的简写。
$x *= 2**=AssignmentRight-associative$x = $x ** $y 的简写。
$x **= 2/=AssignmentRight-associative$x = $x / $y 的简写。
$x /= 2.=AssignmentRight-associative$x = $x . $y 的简写。
$msg .= ' done'%=AssignmentRight-associative$x = $x % $y 的简写。
$x %= 3&=AssignmentRight-associative$x = $x & $y 的简写。
$x &= 0xFF|=AssignmentRight-associative$x = $x | $y 的简写。
$x |= 0x01^=AssignmentRight-associative$x = $x ^ $y 的简写。
$x ^= $mask<<=AssignmentRight-associative$x = $x << $y 的简写。
$x <<= 2>>=AssignmentRight-associative$x = $x >> $y 的简写。
$x >>= 2??=AssignmentRight-associativePHP 7.4 起,若左侧为 null 或未定义则将右侧赋给它。
$cfg['port'] ??= 80andLogical KeywordsLeft-associative等价于 && 但优先级更低,常用于赋值后判断。
$ok = doX() and doY()xorLogical KeywordsLeft-associative两个布尔值不同返回 true。优先级低于 and。
$a xor $borLogical KeywordsLeft-associative等价于 || 但优先级更低,常用于错误回退。
$fp = fopen($f, 'r') or die('open fail')In PHP development, operator precedence and associativity determine the evaluation order of expressions. Misunderstanding these can lead to unexpected results. The PHP Operator Precedence Checker helps you quickly look up the precedence level and associativity direction of any PHP operator to avoid logical errors. Based on the official PHP documentation's operator precedence table, this tool allows you to enter an operator's name or symbol to instantly see its position in the complete precedence list.
The precedence data provided by this tool is based on the official PHP 8.x documentation. Different versions may have slight variations, though they are generally backward compatible. Searches are case-insensitive, but logical operators like "and", "or", and "xor" are typically lowercase. If an operator does not exist, the tool will indicate no results. This tool is for reference only; in actual development, it is highly recommended to use parentheses in complex expressions to improve readability.
In PHP, operator precedence follows a strict table, and associativity determines the evaluation order of operators with the same precedence. For example, the expression "$a - $b - $c" is equivalent to "($a - $b) - $c" because the subtraction operator is left-associative. Conversely, the assignment operator "=" is right-associative, making "$a = $b = 5" equivalent to "$a = ($b = 5)". You can use this tool to quickly verify the precedence of special operators like "??" (null coalescing) and "<=>" (spaceship) to avoid confusion in complex expressions. A common mistake is mixing "&&" and "and". Note that "and" has lower precedence than "&&", which can cause assignments to execute prematurely. For instance, "$result = true && false" returns false, whereas "$result = true and false" returns true because "=" has higher precedence than "and".

PHP Password Hash Generator
Generate PHP password_hash values online. Supports BCrypt, Argon2I, and Argon2ID algorithms for secure password storage.

JSON to PHP Class Generator
Automatically convert JSON data structures into PHP classes with support for type hinting and nested objects to boost development efficiency.

HTML to PHP Converter
Quickly convert HTML code into PHP scripts for dynamic web development. Easily integrate PHP logic and improve code modularity and efficiency.

JSON to PHP Array Converter
Quickly convert JSON data into ready-to-use PHP array code. Perfect for API integration and configuration migration.

PHP Password Hash Generator
Generate PHP password_hash values online. Supports BCrypt, Argon2I, and Argon2ID algorithms for secure password storage.

JSON to PHP Class Generator
Automatically convert JSON data structures into PHP classes with support for type hinting and nested objects to boost development efficiency.

HTML to PHP Converter
Quickly convert HTML code into PHP scripts for dynamic web development. Easily integrate PHP logic and improve code modularity and efficiency.

JSON to PHP Array Converter
Quickly convert JSON data into ready-to-use PHP array code. Perfect for API integration and configuration migration.
PHP Code Formatter & Beautifier
Free online PHP code formatter and beautifier. Automatically format, indent, and organize your PHP scripts to improve readability instantly.