matlab 运算子图
Today we will look into PHP operators. Earlier we went through PHP tutorial for beginners to get you started with variables and String.
今天,我们将研究PHP运算符。 之前,我们为初学者提供了PHP教程,以帮助您开始使用变量和String。
PHP运算子 (PHP Operators)
We can use PHP operators with String, integers, boolean and arrays.
我们可以将PHP运算符与String,integer,boolean和arrays一起使用。
PHP运算符类型 (PHP Operator Types)
PHP scripting language provides different kinds of operators to work with variables such as arithmetic operators, comparison and logical operators.
PHP脚本语言提供了各种运算符来使用变量,例如算术运算符,比较运算符和逻辑运算符。
- PHP Arithmetic Operators PHP算术运算符
- PHP Assignment Operators PHP赋值运算符
- PHP Increment/Decrement Operators PHP增/减运算符
- PHP Comparison Operators PHP比较运算符
- PHP Logical Operators PHP逻辑运算符
- PHP Bitwise Operators PHP按位运算符
- PHP Array Operators PHP数组运算符
- PHP Type Operator PHP类型运算符
1. PHP算术运算符 (1. PHP Arithmetic Operators)
Operator |
Name |
Description |
a+b |
Addition |
Sum of variables a and b, for example 2+3=5 |
a-b |
Subtraction |
Difference of a and b, for example 5-2=3 |
a*b |
Multiplication |
Product of a and b, for example 5*2=10 |
a/b |
Division |
Quotient of a and b, for example 10/2=5 |
a%b |
Modulus |
Remainder of a divided by b, for example 3%2=1 |
-a |
Negation |
Opposite of x, for example -5 |
a.b |
Concatenation |
Used to concat, for example “Pankaj” . “Kumar”=”PankajKumar” |
操作员 |
名称 |
描述 |
a + b |
加成 |
变量a和b的总和,例如2 + 3 = 5 |
b |
减法 |
a和b之差,例如5-2 = 3 |
a * b |
乘法 |
a和b的乘积,例如5 * 2 = 10 |
a / b |
师 |
a和b的商,例如10/2 = 5 |
a%b |
模量 |
a的余数除以b,例如3%2 = 1 |
-一个 |
否定 |
与x相反,例如-5 |
b |
级联 |
用于连接,例如“ Pankaj”。 “ Kumar” =“ PankajKumar” |
";
//subtraction example
$sub = $a - $b;
echo $sub; //prints 5
echo "
";
//multiplication example
$mul = $a * $b;
echo $mul; //prints 50
echo "
";
//division example
$div = $a / $b;
echo $div; // prints 2
echo "
";
echo $a/$c; //prints 3.3333333333333
echo "
";
echo $d/$c; //prints 2.6666666666667
echo "
";
//modulus example
$mod= $a % $b;
echo $mod;
echo "
"; //prints 0
//Negation example
$neg = -$a;
echo $neg; //prints -10;
echo "
";
//Concatenation example
$str1="Pankaj";
$str2="Kumar";
echo $str1 . " " . $str2; //prints "Pankaj Kumar"
echo "
";
echo $a . $b; //prints 105
echo "
";
echo $c . $d; //prints 38
?>
2. PHP赋值运算符 (2. PHP Assignment Operators)
Operator |
Description |
a=b |
The value of b will be set to a, the left side can be expressions also, for example a= 10-5 |
a+=b |
Same as a=a+b |
a-=b |
Same as a=a-b |
a*=b |
Same as a=a*b |
a/=b |
Same as a=a/b |
a%=b |
Same as a=a%b |
a.=b |
Same as a=a.b |
操作员 |
描述 |
a = b |
b的值将设置为a,左侧也可以是表达式,例如a = 10-5 |
a + = b |
与a = a + b相同 |
a- = b |
与a = ab相同 |
a * = b |
与a = a * b相同 |
a / = b |
与a = a / b相同 |
a%= b |
与a = a%b相同 |
a。= b |
与a = ab相同 |
";
$a+=$b;
echo $a; //prints 24, same as a=a+b
echo "
";
$a-=$b;
echo $a; //prints 12, same as a=a-b=24-12
echo "
";
$a*=$b;
echo $a; //prints 144, same as a=a*b=12*12
echo "
";
$a/=$b;
echo $a; //prints 12, same as a=a/b=144/12
echo "
";
$a%=$b;
echo $a; //prints 0, same as a=a%b=12%12
echo "
";
$a.=$b;
echo $a; //prints 012, same as a=a.b=0.12=012
?>
3. PHP增/减运算符 (3. PHP Increment/Decrement Operators)
Operator |
Name |
Description |
++a |
Pre-increment |
Increment a by 1 and then returns it |
a++ |
Post-increment |
returns a and then increment it by 1 |
–a |
Pre-decrement |
Decrement a by 1 and then returns it |
a– |
Post-decrement |
returns a and then decrement it by 1 |
操作员 |
名称 |
描述 |
++一 |
预增量 |
将a递增1,然后返回 |
a ++ |
后增量 |
返回a然后将其递增1 |
-一个 |
递减 |
将a减1,然后返回 |
一个- |
递减后 |
返回a,然后减1 |
";
//Post-increment example
$b=$a++;
echo "a=".$a." ,b=".$b; //prints a=14 ,b=13
echo "
";
//Pre-decrement example
$b=--$a;
echo "a=".$a." ,b=".$b; //prints a=13 ,b=13
echo "
";
//Post-decrement example
$b=$a--;
echo "a=".$a." ,b=".$b; //prints a=12 ,b=13
echo "
";
?>
4. PHP比较运算符 (4. PHP Comparison Operators)
Operator |
Name |
Description |
a==b |
Equal |
True if a is equal to b |
a===b |
Identical |
True if a is equal to b and of same type, 5===”5” is false |
a!=b |
Not equal |
True if a and b are not equal |
a<>b |
Not equal |
True if a and b are not equal |
a!==b |
Not identical |
True if a and b are not equal and they are not of same type, for example 5!==”5″ returns true |
a
| Less than |
True if a is less than b |
a>b |
Greater than |
True if a is greater than b |
a<=b |
Less than or equal to |
True if a is less than or equal to b |
a>=b |
Greater than or equal to |
True if a is greater than or equal to b |
操作员 |
名称 |
描述 |
a == b |
等于 |
如果a等于b,则为真 |
a === b |
相同 |
如果a等于b并且具有相同类型,则为true,则5 ===“ 5”为false |
a!= b |
不相等 |
如果a和b不相等则为真 |
a <> b |
不相等 |
如果a和b不相等则为真 |
a!== b |
不一样 |
如果a和b不相等并且不是同一类型,则为true,例如5!==“ 5”返回true |
a
| 少于 |
如果a小于b,则为true |
a> b |
比...更棒 |
如果a大于b,则为true |
a <= b |
小于或等于 |
如果a小于或等于b,则为true |
a> = b |
大于或等于 |
如果a大于或等于b,则为true |
";
var_dump($a==$c); //prints bool(true)
echo "
";
//Identical example
var_dump($a===$b); //prints bool(false)
echo "
";
var_dump($a===$c); //prints bool(true)
echo "
";
//Not equal example
var_dump($a!=$b); //prints bool(false)
echo "
";
var_dump($a!=$c); //prints bool(false)
echo "
";
var_dump($a<>$b); //prints bool(false)
echo "
";
var_dump($a<>$c); //prints bool(false)
echo "
";
//Not identical example
var_dump($a!==$b); //prints bool(true)
echo "
";
var_dump($a!==$c); //prints bool(false)
echo "
";
//Less than example
var_dump($a<$b); //prints bool(false)
echo "
";
var_dump($a<$d); //prints bool(false)
echo "
";
//Greater than example
var_dump($a>$b); //prints bool(false)
echo "
";
var_dump($a>$d); //prints bool(true)
echo "
";
//Less than or equal to example
var_dump($a<=$b); //prints bool(true)
echo "
";
var_dump($a<=$d); //prints bool(false)
echo "
";
//Greater than or equal to example
var_dump($a>=$b); //prints bool(true)
echo "
";
var_dump($a>=$d); //prints bool(true)
echo "
";
?>
5. PHP逻辑运算符 (5. PHP Logical Operators)
Operator |
Name |
Description |
a and b |
And |
True if both a and b are true |
a or b |
Or |
True if either a or b is true |
a xor b |
Xor |
True if either a or b is true, but not both |
!a |
Not |
True if a is not true |
a && b |
And |
Same as and operator |
a || b |
Or |
Same as or operator |
操作员 |
名称 |
描述 |
a和b |
和 |
如果a和b都为真,则为真 |
a或b |
要么 |
如果a或b为真,则为真 |
异或 |
异或 |
如果a或b为真,则为True,但不能同时为真 |
!一个 |
不 |
如果a不为真,则为真 |
a && b |
和 |
与和运算符相同 |
|| b |
要么 |
与或运算子相同 |
";
//Or example
var_dump($a or $b); //prints bool(true)
var_dump($a or $c); //prints bool(true)
var_dump($a || $b); //prints bool(true)
var_dump($a || $c); //prints bool(true)
echo "
";
//Xor example
var_dump($a xor $b); //prints bool(true)
var_dump($a xor $c); //prints bool(false)
echo "
";
//Not example
var_dump(!$a); //prints bool(false)
var_dump(!$b); //prints bool(true)
echo "
";
?>
6. PHP按位运算符 (6. PHP Bitwise Operators)
Operator |
Name |
Description |
a & b |
And |
Bits that are set in both a and b are set. |
a | b |
Or |
Bits that are set in either a or b are set |
a ^ b |
Xor |
Bits that are set in a or b but not both are set |
~ a |
Not |
Bits that are set in a are not set, and vice versa |
a << b |
Shift left |
Shift the bits of a, b steps to the left |
a >> b |
Shift right |
Shift the bits of a, b steps to the right |
操作员 |
名称 |
描述 |
a和b |
和 |
在a和b中设置的位均被置位。 |
一个| b |
要么 |
设置在a或b中设置的位 |
a ^ b |
异或 |
在a或b中设置但未同时设置的位 |
〜一个 |
不 |
a中设置的位未设置,反之亦然 |
a << b |
左移 |
将a, b的位向左移动 |
a >> b |
右移 |
将a, b的位向右移动 |
";
//Bitwise Or example
$c=$a | $b;
// 00001111
// |00100011
// 00101111
echo $c; //prints 47
echo "
";
//Bitwise Xor example
$c=$a ^ $b;
// 00001111
// ^00100011
// 00101100
echo $c; //prints 44
echo "
";
//Bitwise Not example
$c=$a & ~$b; //bits that are set in a but not in b, 00001100 = 12
$d=$b & ~$a; //bits that are set in b but not in a, 00100000 = 32
echo $c; //prints 12
echo "
";
echo $d; //prints 32
echo "
";
//Shift left example
$c=$a<<2; //bits shifted to left two places, 00111100 = 60
echo $c; //prints 60
echo "
";
//Shift right example
$c=$a>>2; //bits shifted to right two places, 00000011 = 3
echo $c; //prints 3
?>
7. PHP数组运算符 (7. PHP Array Operators)
Operator |
Name |
Description |
a + b |
Union |
Union of a and b |
a == b |
Equality |
True if a and b have same key/value pairs |
a === b |
Identity |
True if a and b have the same key/value pairs in the same order and of the same types. |
a != b |
Inequality |
True if a is not equal to b |
a <> b |
Inequality |
True if a is not equal to b |
a !== b |
Non-Identity |
True if a is not identical to b |
操作员 |
名称 |
描述 |
a + b |
联盟 |
a和b的并集 |
a == b |
平等 |
如果a和b具有相同的键/值对,则为true |
a === b |
身分识别 |
如果a和b具有相同顺序和相同类型的相同键/值对,则为true。 |
a!= b |
不等式 |
如果a不等于b为真 |
a <> b |
不等式 |
如果a不等于b为真 |
a!== b |
非身份 |
如果a与b不相同,则为true |
";
//Arrays Equality
$cars1=array("BMW","2" => "Honda",1 => "Toyota");
var_dump($cars == $cars1); //prints bool(true);
var_dump($cars == $buses); //prints bool(false);
echo "
";
//Identical Arrays operator
var_dump($cars === $cars1); //prints bool(false);
var_dump($cars === $buses); //prints bool(false);
echo "
";
//Inequality example
var_dump($cars != $cars1); //prints bool(false);
var_dump($cars != $buses); //prints bool(true);
echo "
";
var_dump($cars <> $cars1); //prints bool(false);
var_dump($cars <> $buses); //prints bool(true);
echo "
";
//Non-Identical Arrays operator
var_dump($cars !== $cars1); //prints bool(true);
var_dump($cars !== $buses); //prints bool(true);
echo "
";
?>
8. PHP类型运算符 (8. PHP Type Operator)
instanceof is the type operator used to determine if a PHP variable is an instantiated object of a class or not.
instanceof是用于确定PHP变量是否为类的实例化对象的类型运算符。
That’s all for PHP operators. In the next tutorial, we will learn about PHP Conditional Statements, Arrays and Loops in PHP.
PHP运算符就这些了。 在下一个教程中,我们将学习PHP中PHP条件语句,数组和循环。
翻译自: https://www.journaldev.com/1477/php-operators
matlab 运算子图