1. 首页
  2. php

PHP – 运算符类型

使用表达式4 + 5等于9可以给出简单的答案。这里4和5被称为操作数,+被称为操作符。PHP语言支持以下类型的运算符。

  • 算术运算符
  • 比较运算符
  • 逻辑(或关系)运算符
  • 分配运营商
  • 条件(或三元)运算符

让我们逐一了解所有运营商。

PHP - 运算符类型

算术运算符

PHP语言支持以下算术运算符 –

假设变量A保持10,变量B保持20然后 –

操作者 描述
+ 添加两个操作数 A + B将给出30
从第一个减去第二个操作数 A – B将给-10
* 将两个操作数相乘 A * B将给出200
/ 用除分子除分子 B / A会给2
模数运算符和整数除法后的余数 B%A将给出0
++ 递增运算符,将整数值增加1 A ++将给出11
递减运算符,将整数值减一 A–会给9

比较运算符

PHP语言支持以下比较运算符

假设变量A保持10,变量B保持20然后 –

操作者 描述
== 检查两个操作数的值是否相等,如果是,则条件变为真。 (A == B)不是真的。
!= 检查两个操作数的值是否相等,如果值不相等则条件变为true。 (A!= B)是真的。
> 检查左操作数的值是否大于右操作数的值,如果是,则条件变为真。 (A> B)不是真的。
< 检查左操作数的值是否小于右操作数的值,如果是,则条件变为真。 (A <B)是真的。
> = 检查左操作数的值是否大于或等于右操作数的值,如果是,则条件变为真。 (A> = B)不是真的。
<= 检查左操作数的值是否小于或等于右操作数的值,如果是,则条件变为真。 (A <= B)是真的。

逻辑运算符

PHP语言支持以下逻辑运算符

假设变量A保持10,变量B保持20然后 –

操作者 描述
称为逻辑AND运算符。如果两个操作数均为真,则条件成立。 (A和B)是真的。
要么 称为逻辑OR运算符。如果两个操作数中的任何一个非零,则条件变为真。 (A或B)是真的。
&& 称为逻辑AND运算符。如果两个操作数都不为零,则条件成立。 (A && B)是真的。
|| 称为逻辑OR运算符。如果两个操作数中的任何一个非零,则条件变为真。 (A || B)是真的。
称为逻辑非运算符。用于反转其操作数的逻辑状态。如果条件为真,则Logical NOT运算符将为false。 !(A && B)是假的。

分配运营商

PHP语言支持以下赋值运算符 –

操作者 描述
= 简单赋值运算符,将右侧操作数的值分配给左侧操作数 C = A + B将A + B的值分配给C
+ = 添加AND赋值运算符,它将右操作数添加到左操作数并将结果赋给左操作数 C + = A等于C = C + A.
– = 减去AND赋值运算符,它从左操作数中减去右操作数,并将结果赋给左操作数 C – = A相当于C = C – A.
* = 乘以AND赋值运算符,它将右操作数与左操作数相乘,并将结果赋值给左操作数 C * = A等于C = C * A.
/ = 除法AND赋值运算符,它将左操作数除以右操作数,并将结果赋值给左操作数 C / = A等于C = C / A.
%= 模数AND赋值运算符,它使用两个操作数的模数并将结果赋给左操作数 C%= A等于C = C%A

条件运算符

还有一个运算符叫做条件运算符。这首先计算true或false值的表达式,然后根据评估结果执行两个给定语句中的一个。条件运算符具有以下语法 –

操作者 描述
?: 条件表达 如果条件为真?然后是值X:否则为Y值

运营商类别

我们上面讨论过的所有运营商都可以分为以下几类 –

  • 一元前缀运算符,位于单个操作数之前。
  • 二进制运算符,它接受两个操作数并执行各种算术和逻辑运算。
  • 条件运算符(三元运算符),它接受三个操作数并根据第一个表达式的求值来计算第二个或第三个表达式。
  • 赋值运算符,它为变量赋值。

PHP运算符的优先级

运算符优先级确定表达式中的术语分组。这会影响表达式的计算方式。某些运营商的优先级高于其他运营商; 例如,乘法运算符的优先级高于加法运算符 –

例如x = 7 + 3 * 2; 这里x被赋予13,而不是20,因为operator *的优先级高于+,所以它首先乘以3 * 2然后加到7。

此处具有最高优先级的运算符显示在表的顶部,具有最低优先级的运算符显示在底部。在表达式中,将首先评估更高优先级的运算符。

类别 操作者 关联性
一元 !++ – 右到左
* /% 左到右
添加剂 + – 左到右
相关的 << => = 左到右
平等 ==!= 左到右
逻辑和 && 左到右
逻辑或 || 左到右
条件 右到左
分配 = + = – = * = / =%= 右到左

原创文章,作者:零久SEO,如若转载,请注明出处:http://www.seo0j.com/298.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注

评论列表(15条)

  • 舟州知名博主 2019年5月5日 下午12:16

    php相关的教程可以深入一点,对于php高深的对我们还是有帮助

  • nike lebron 17 2020年2月23日 上午5:21

    I needed to send you this little bit of note just to give many thanks once again for those precious suggestions you’ve documented here. This has been simply incredibly generous of you to make easily all that some people would have sold for an e book to help make some profit on their own, mostly given that you might have tried it if you ever desired. The good tips in addition worked as the easy way to be aware that other individuals have a similar zeal just as my very own to grasp a good deal more on the topic of this condition. I know there are some more fun times in the future for individuals who look into your site.

  • golden goose 2020年2月25日 下午11:00

    I just wanted to send a small word to be able to say thanks to you for some of the remarkable steps you are giving at this site. My extensive internet search has now been recognized with reputable tips to exchange with my friends and classmates. I ‘d claim that most of us visitors are unquestionably fortunate to dwell in a wonderful community with very many awesome professionals with valuable tactics. I feel extremely blessed to have come across the website page and look forward to many more exciting times reading here. Thank you once again for everything.

  • yeezy boost 350 v2 2020年2月28日 上午8:49

    I have to show some thanks to you just for bailing me out of such a condition. Right after scouting through the internet and getting concepts which are not productive, I assumed my life was over. Being alive without the solutions to the problems you have resolved by way of your guide is a crucial case, and those which could have badly affected my entire career if I had not encountered your blog. Your actual know-how and kindness in handling all the pieces was crucial. I don’t know what I would have done if I had not come upon such a thing like this. I’m able to now look ahead to my future. Thank you very much for this skilled and amazing help. I will not hesitate to propose your web blog to anyone who would need support on this matter.

  • balenciaga 2020年3月2日 上午4:09

    Needed to create you that very little observation so as to give many thanks as before for the marvelous advice you’ve discussed at this time. It’s quite remarkably open-handed of people like you to present unhampered all a lot of folks could have advertised as an e-book in order to make some money on their own, most importantly now that you might have done it if you ever considered necessary. These guidelines as well worked as the fantastic way to comprehend some people have the identical zeal similar to my very own to grasp whole lot more when it comes to this issue. Certainly there are some more pleasurable times in the future for folks who go through your website.

  • nike kd 11 2020年3月4日 下午7:24

    My spouse and i have been now fulfilled Albert could conclude his research through your ideas he got out of the web page. It’s not at all simplistic to simply happen to be making a gift of secrets which many people could have been making money from. We grasp we have you to appreciate because of that. The main illustrations you have made, the straightforward blog menu, the relationships you can assist to foster – it’s mostly amazing, and it’s facilitating our son and our family recognize that this article is thrilling, which is certainly pretty pressing. Many thanks for the whole thing!

  • christian louboutin 2020年3月7日 上午6:12

    My husband and i have been absolutely delighted that Michael could finish up his investigations because of the ideas he obtained out of your web page. It’s not at all simplistic to just continually be giving for free guidelines which often some other people may have been trying to sell. Therefore we realize we now have the writer to be grateful to because of that. All the illustrations you’ve made, the easy site navigation, the relationships you will help promote – it’s all powerful, and it is leading our son and us understand that content is enjoyable, and that’s pretty essential. Thank you for the whole thing!

  • bape clothing 2020年3月10日 上午1:05

    Needed to send you one very little remark to help thank you so much the moment again for those pleasing suggestions you’ve discussed in this case. It is simply generous of you in giving without restraint what exactly numerous people would’ve sold for an ebook in order to make some dough on their own, notably seeing that you could have tried it if you considered necessary. Those tricks likewise worked to provide a fantastic way to fully grasp that many people have similar keenness like my personal own to understand whole lot more when it comes to this issue. I am certain there are thousands of more pleasurable instances ahead for folks who scan your site.

  • off-white 2020年3月13日 上午6:19

    I’m just commenting to let you know what a great discovery my friend’s princess developed viewing your blog. She discovered many details, most notably what it is like to have a wonderful teaching style to have the rest clearly learn about a variety of impossible topics. You really exceeded our expected results. I appreciate you for imparting those productive, trusted, explanatory and also fun thoughts on this topic to Lizeth.

  • michael kors outlet online 2020年3月16日 上午5:50

    I want to get across my appreciation for your kindness supporting folks that have the need for guidance on this one theme. Your special commitment to passing the solution all through became rather practical and have without exception enabled individuals like me to attain their ambitions. The helpful recommendations indicates much to me and far more to my colleagues. Many thanks; from each one of us.

  • kanye west yeezy 2020年3月19日 上午12:35

    I’m just writing to let you know of the beneficial experience my friend’s girl obtained viewing your blog. She even learned lots of things, most notably what it is like to possess a wonderful coaching mindset to let most people just comprehend specific tricky issues. You really did more than our own expected results. I appreciate you for showing such invaluable, safe, informative and fun guidance on this topic to Janet.

  • coach factory outlet 2020年3月21日 上午11:12

    I have to express some thanks to the writer just for rescuing me from such a problem. Because of surfing through the the net and seeing recommendations which were not productive, I believed my life was done. Existing without the presence of solutions to the difficulties you’ve sorted out through your main article content is a critical case, as well as the kind which might have in a wrong way damaged my career if I hadn’t noticed your site. Your mastery and kindness in maneuvering every aspect was priceless. I am not sure what I would’ve done if I had not encountered such a stuff like this. I am able to at this time look ahead to my future. Thanks very much for this expert and results-oriented guide. I will not be reluctant to recommend your blog to any individual who wants and needs tips about this subject matter.

  • jordan 1 off white 2020年3月24日 上午6:42

    I enjoy you because of your own hard work on this web site. Betty take interest in engaging in investigations and it is easy to understand why. Most people learn all relating to the lively means you render effective tips and tricks via your website and therefore invigorate response from other individuals on that situation while my girl has been discovering a whole lot. Take advantage of the rest of the new year. You have been doing a tremendous job.

  • nike air max 270 2020年3月27日 上午2:13

    I as well as my buddies came digesting the excellent things found on your web site and suddenly I had an awful suspicion I never expressed respect to you for those tips. Most of the women came absolutely joyful to read through all of them and now have certainly been tapping into them. Many thanks for simply being indeed accommodating and then for choosing varieties of smart resources most people are really eager to learn about. Our honest regret for not saying thanks to you sooner.

联系我们

15555333984

在线咨询:点击这里给我发消息

邮件:lxa6@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

QR code