วันศุกร์ที่ 28 กุมภาพันธ์ พ.ศ. 2563

PHP Operators


= ดำเนินการกำหนดจะใช้ในการกำหนดค่าให้กับตัวแปรใน PHP

+ ดำเนินการทางคณิตศาสตร์ที่ใช้ในการเพิ่มค่ากัน

ดำเนินการทางคณิตศาสตร์

ตารางด้านล่างแสดงดำเนินการทางคณิตศาสตร์ใน PHP:

OperatorNameDescriptionExampleResult
x + yAdditionSum of x and y2 + 24
x - ySubtractionDifference of x and y5 - 23
x * yMultiplicationProduct of x and y5 * 210
x / yDivisionQuotient of x and y15 / 53
x % yModulusRemainder of x divided by y5 % 2
10 % 8
10 % 2
1
2
0
- xNegationOpposite of x- 2 

Assignment Operators

ดำเนินการกำหนดขั้นพื้นฐานใน PHP เป็น "=" ก็หมายความว่าตัวถูกดำเนินการทางด้านซ้ายได้รับการกำหนดมูลค่าของการแสดงออกทางด้านขวา นั่นคือคุณค่าของ "$ x = 5" คือ 5
AssignmentSame as...Description
x = yx = yThe left operand gets set to the value of the expression on the right
x += yx = x + yAddition
x -= yx = x - ySubtraction
x *= yx = x * yMultiplication
x /= yx = x / yDivision
x %= yx = x % yModulus
x .= yx = x . yConcatenate two strings

Incrementing/Decrementing Operators

OperatorNameDescription
++ xPre-incrementIncrements x by one, then returns x
x ++Post-incrementReturns x, then increments x by one
-- xPre-decrementDecrements x by one, then returns x
x --Post-decrementReturns x, then decrements x by one

Comparison Operators

Comparison operators allows you to compare two values:
OperatorNameDescriptionExample
x == yEqualTrue if x is equal to y5==8 returns false
x === yIdenticalTrue if x is equal to y, and they are of same type5==="5" returns false
x != yNot equalTrue if x is not equal to y5!=8 returns true
x <> yNot equalTrue if x is not equal to y5<>8 returns true
x !== yNot identicalTrue if x is not equal to y, or they are not of same type5!=="5" returns true
x > yGreater thanTrue if x is greater than y5>8 returns false
x < yLess thanTrue if x is less than y5<8 returns true
x >= yGreater than or equal toTrue if x is greater than or equal to y5>=8 returns false
x <= yLess than or equal toTrue if x is less than or equal to y5<=8 returns true

Logical Operators

OperatorNameDescriptionExample
x and yAndTrue if both x and y are truex=6
y=3
(x < 10 and y > 1) returns true
x or yOrTrue if either x and y is truex=6
y=3
(x==6 or y==5) returns true
x xor yXorTrue if either x and y is true, but not bothx=6
y=3
(x==6 or y==3) returns false
x && yAndTrue if both x and y are truex=6
y=3
(x < 10 && y > 1) returns true
x || yOrTrue if either x and y is truex=6
y=3
(x==5 || y==5) returns false
! xNotTrue if x is not truex=6
y=3
!(x==y) returns true

Array Operators

OperatorNameDescription
x + yUnionUnion of x and y
x == yEqualityTrue if x and y have the same key/value pairs
x === yIdentityTrue if x and y have the same key/value pairs in the same order and of the same types
x != yInequalityTrue if x is not equal to y
x <> yInequalityTrue if x is not equal to y
x !== yNon-identityTrue if x is not identical to y

ไม่มีความคิดเห็น:

แสดงความคิดเห็น