Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic operators of PHP

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "what are the basic operators of PHP". In daily operation, I believe many people have doubts about what are the basic operators of PHP. Xiaobian consulted all kinds of information and sorted out simple and easy operation methods. I hope to help you answer the doubts of "what are the basic operators of PHP"! Next, please follow the small series to learn together!

PHP operators

Operators are symbols that produce another value through one or more expressions. There are many operators, such as "+","%",". "All are operators. So let's take a look at the application of PHP's different operators.

PHP arithmetic operators

"+" addition operation, for example: $a+$b;

"-" subtraction operation, for example: $a-$b;

"*" multiplication operation, for example: $a*$b;

"/" division operation, for example: $a/$b;

"%" remainder operation (modulo operation), e.g.$a%$b;

Output:

It follows that using different arithmetic operators yields different results.

PHP assignment operators

We call = (equal sign) an assignment operator in PHP operators, which is used to assign variables, that is, assign the value on the right side of the equal sign to the variable on the left side of the equal sign, and the variable on the left side is the value on the right side.

"+=" addition example: $x += $y, that is: $x = $x + $y, the variable on the left of the operator plus the value on the right is assigned to the variable on the left.

"-=" subtraction example: $x -= $y, that is: $x = $x - $y, subtract the value on the right from the variable on the left of the operator and assign it to the variable on the left.

" *=" multiplication example: $x *= $y, that is: $x = $x * $y, multiply the variable on the left of the operator by the value on the right and assign it to the variable on the left.

"/=" division example: $x /= $y, that is: $x = $x / $y, divide the variable on the left of the operator by the value on the right and assign it to the variable on the left.

"%=" remainder example: $x %= $y, that is: $x = $x % $y, the variable on the left of the operator is modulo the value on the right, and the result is assigned to the variable on the left.

".= "Example of splicing: $x .= $y = $x . $y, appends the character on the right to the left.

Output:

Thus: $x += $y is equivalent to $x = $x + $y.

PHP string operators

There is only one string operator, namely the English period ". "It is to join two strings and splice them into a new string.

Output:

PHP increment/decrement operators

In our everyday use, arithmetic operators are suitable for use when there are two or more different operands, but when there is only one operand, the increment "++" or decrement "--" operator can be used.

Increasing or decreasing a variable by 1 and then assigning the value to the original variable is called a preincrement or decrement operator (preincrement and decrement operator);

Putting the operator after a variable, that is, returning the current value of the variable first, and then increasing or decreasing the value of the variable by 1, is called a post-increment or decrement operator (post-increment and decrement operator).

Output:

PHP comparison operators

PHP comparison operators compare two values (numbers or strings)

== is used to compare equals, e.g.$x == $y, returns true if $x equals $y.

=== is used to compare congruence (identical), e.g.$x === $y, returns true if $x equals $y and they are of the same type

!= Used to compare not equal, e.g.$x != $y returns true if $x is not equal to $y.

Used to compare not equal, e.g.$x $y, returns true if $x is not equal to $y.

!== Used to compare incongruities (completely different), e.g.$x !== $y returns true if $x is not equal to $y and they are of different types.

> Used to compare greater than, e.g.$x > $y, returns true if $x is greater than $y.

= is used to compare greater than or equal to, for example: $x >= $y, if $x is greater than or equal to $y, then return true.

Output:

Output every day up, so just output false interval.

Output:

The output is blessed, logical or, one of which is true, so the output is true interval.

Output:

Output good learning, logical not, flase into true, output true.

At this point, the study of "what are the basic operators of PHP" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report