The reference methods of static methods and static properties in classes
such as
class Test{
public static $test = 1;
public static function test(){
}
}
can directly use Test::$test to obtain the value of the $test property without instantiating the object
statically The same is true for method calls Test::test(); directly call the static method test
=>
keys generally used for arrays => values
->
objects generally used for objects -> object properties and objects -> object methods
=== : compare the size, and also compare whether the types are the same
== : only compare the size
Operator Description
<<< Pipe, introduced from c++. The content enclosed by the following tags is treated as a string, and the variables in it will be expanded
<< left shift, bit operator
>> right shift, bit operator
== equal, logical operator. Automatic conversion of the data types involved in the operand
=== Identical equals, logical operator. Do not convert data type
>>> no such operator
PHP arithmetic operators
operator name example result+ | addition | $x + $y | sum $x and $y |
- | subtraction | $x - $y | difference between $x and $y |
* | multiplication | $x * $y | Product of $x and $y |
/ | division | $x / $y | Quotient of $x and $y |
% | modulus | $x % $y | Remainder of $x divided by $y |
The following examples show different results using different arithmetic operators:
example
<?php $x=10; $y=6; echo ($x + $y); // prints 16 echo ($x - $y); // prints 4 echo ($x * $y); // prints 60 echo ($x / $y); // output 1.6666666666667 echo ($x % $y); // output 4 ?>
PHP assignment operator
The PHP assignment operator is used to write values to variables.
The basic assignment operator in PHP is "=". This means that the right-hand assignment expression sets the value of the left-hand operand.
Assignment is equivalent to descriptionx = y | x = y | The expression on the right sets the value for the operand on the left. |
x += y | x = x + y | add |
x -= y | x = x - y | reduce |
x *= y | x = x * y | take |
x /= y | x = x / y | remove |
x %= y | x = x % y | modulus |
The following examples show different results using different assignment operators:
example
<?php $x=10; echo $x; // output 10 $y=20; $y += 100; echo $y; // output 120 $ z = 50; $ z - = 25; echo $z; // output 25 $i=5; $i *= 6; echo $i; // output 30 $j=10; $j /= 5; echo $j; // output 2 $k=15; $k %= 4; echo $k; // output 3 ?>
PHP string operators
operator name example result. | tandem | $txt1 = "Hello" $txt2 = $txt1 . " world!" | $txt2 now contains "Hello world!" |
.= | concatenation assignment | $txt1 = "Hello" $txt1 .= " world!" | $txt1 now contains "Hello world!" |
The following example shows the result of using string operators:
example
<?php $a = "Hello"; $b = $a . " world!"; echo $b; // print Hello world! $x="Hello"; $x .= " world!"; echo $x; // output Hello world! ?>
PHP increment/decrement operators
operator name description++$x | pre-increment | Increment $x by one, then return $x |
$x++ | post increment | Returns $x, then increments $x by one |
--$x | pre-decrement | Decrement $x by one, then return $x |
$x-- | post decrement | Return $x, then decrement $x by one |
The following examples show different results using different increment/decrement operators:
example
<?php $x=10; echo ++$x; // output 11 $y=10; echo $y++; // output 10 $ z = 5; echo --$z; // output 4 $i=5; echo $i--; // output 5 ?>
PHP comparison operators
PHP comparison operators are used to compare two values (numbers or strings):
operator name example result== | equal | $x == $y | Returns true if $x is equal to $y. |
=== | Congruent (exactly the same) | $x === $y | Returns true if $x is equal to $y and they are of the same type. |
!= | not equal to | $x != $y | Returns true if $x is not equal to $y. |
<> | not equal to | $x <> $y | Returns true if $x is not equal to $y. |
!== | not equal (completely different) | $x !== $y | Returns true if $x is not equal to $y and they are not of the same type. |
> | more than the | $x > $y | Returns true if $x is greater than $y. |
< | more than the | $x < $y | Returns true if $x is less than $y. |
>= | greater than or equal to | $x >= $y | Returns true if $x is greater than or equal to $y. |
<= | less than or equal to | $x <= $y | Returns true if $x is less than or equal to $y. |
The following examples show different results using some comparison operators:
example
<?php $x=100; $y="100"; var_dump($x == $y); echo "<br>"; var_dump($x === $y); echo "<br>"; var_dump($x != $y); echo "<br>"; var_dump($x !== $y); echo "<br>"; $a=50; $b=90; var_dump($a > $b); echo "<br>"; var_dump($a < $b); ?>
PHP logical operators
operator name example resultand | and | $x and $y | Returns true if both $x and $y are true. |
or | or | $x or $y | Returns true if at least one of $x and $y is true. |
xor | XOR | $ x xor $ y | Returns true if one and only one of $x and $y is true. |
&& | and | $x && $y | Returns true if both $x and $y are true. |
|| | or | $x || $y | Returns true if at least one of $x and $y is true. |
! | No | !$x | Returns true if $x is not true. |
PHP array operators
PHP array operators are used to compare arrays:
operator name example result+ | joint | $x + $y | $x 和 $y 的联合(但不覆盖重复的键) |
== | 相等 | $x == $y | 如果 $x 和 $y 拥有相同的键/值对,则返回 true。 |
=== | 全等 | $x === $y | 如果 $x 和 $y 拥有相同的键/值对,且顺序相同类型相同,则返回 true。 |
!= | 不相等 | $x != $y | 如果 $x 不等于 $y,则返回 true。 |
<> | 不相等 | $x <> $y | 如果 $x 不等于 $y,则返回 true。 |
!== | 不全等 | $x !== $y | 如果 $x 与 $y 完全不同,则返回 true。 |
下例展示了使用不同数组运算符的不同结果:
实例
<?php
$x = array("a" => "red", "b" => "green");
$y = array("c" => "blue", "d" => "yellow");
$z = $x + $y; // $x 与 $y 的联合
var_dump($z);
var_dump($x == $y);
var_dump($x === $y);
var_dump($x != $y);
var_dump($x <> $y);
var_dump($x !== $y);
?>