RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
php中数据类型的优先级,php仅支持三种数据类型

php中的运算符优先级是什么样的

下表按照优先级从高到低列出了运算符。同一行中的运算符具有相同优先级,此时它们的结合方向决定求值顺序。

创新互联-专业网站定制、快速模板网站建设、高性价比灵丘网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式灵丘网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖灵丘地区。费用合理售后完善,十余年实体公司更值得信赖。

运算符优先级

结合方向

运算符

附加信息

clone new

clone 和 new

[

array()

**

算术运算符

++

--

~

(int)

(float)

(string)

(array)

(object)

(bool)

@

类型和递增/递减

instanceof

类型

!

逻辑运算符

*

/

%

算术运算符

+

-

.

算术运算符和字符串运算符

位运算符

=

=

比较运算符

==

!=

===

!==

=

比较运算符

位运算符和引用

^

位运算符

|

位运算符

逻辑运算符

||

逻辑运算符

??

比较运算符

? :

ternary

right

=

+=

-=

*=

**=

/=

.=

%=

=

|=

^=

=

=

赋值运算符

and

逻辑运算符

xor

逻辑运算符

or

逻辑运算符

Example #1 结合方向

?php

$a = 3 * 3 % 5; // (3 * 3) % 5 = 4

// ternary operator associativity differs from C/C++

$a = true ? 0 : true ? 1 : 2; // (true ? 0 : true) ? 1 : 2 = 2

$a = 1;

$b = 2;

$a = $b += 3; // $a = ($b += 3) - $a = 5, $b = 5

?

Operator precedence and associativity only determine how expressions

are grouped, they do not specify an order of evaluation. PHP does not

(in the general case) specify in which order an expression is evaluated

and code that assumes a specific order of evaluation should be avoided,

because the behavior can change between versions of PHP or depending on

the surrounding code.

Example #2 Undefined order of evaluation

?php

$a = 1;

echo $a + $a++; // may print either 2 or 3

$i = 1;

$array[$i] = $i++; // may set either index 1 or 2

?

Note:

尽管 = 比其它大多数的运算符的优先级低,PHP

仍旧允许类似如下的表达式:if (!$a = foo()),在此例中

foo() 的返回值被赋给了 $a。

PHP运算符优先级

10-32 为最高优先级

相当于(10-32) ? 0 : true

而后 0 ? 5 : 3

0在计算机中被认为FLASE 因此答案是3

请给分,谢谢~

PHP 表达式优先级问题

你用个括号把and两边括起来不就行了?

关于优先级:""和""大于"||"大于"="大于and大于or

看下这个你就晓得你程序写的有多乱了。

php 优先级问题

php三元运算符的顺序是从左向右的

原始 $a = $b $c ? ($c-$b) ? 1 : ($b-$c) 0 : ($b+$c) ? 0 : $b*$c;

先计算优先级高于三元运算符的

$a = 20 40 ? 20 ? 1 : -20 0 : 60 ? 0 : 800;

$a = 0 ? 20 ? 1 : 0 : 60 ? 0 : 800;

然后从左测第一个可执行的三元运算开始执行 20 ? 1 : 0 为 1

$a = 0 ? 1 : 60 ? 0 : 800;

再从左测第一个可执行的三元运算开始执行 0 ? 1 : 60 为 60

$a = 60 ? 0 : 800;

最终

$a = 0

为了避免工作中出现这种情况,建议避免出现比较长的三元运算表达式


本文题目:php中数据类型的优先级,php仅支持三种数据类型
标题URL:http://scyingshan.cn/article/hccejs.html