Php – Operators

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/php-operators/
PINTEREST
PINTEREST
INSTAGRAM

PHP Tutorial Topics

  1. Introduction To PHP
  2. Installing PHP To Linux
  3. Installing PHP To Windows
  4. PHP Hello World Project with Eclipse
  5. PHP Syntax
  6. PHP Variables and Types
  7. PHP String Types
  8. PHP Numeric Type (Integer, Float, Double)
  9. PHP Boolean Type
  10. PHP Arrays
  11. PHP Operators
  12. PHP Ternary Operators
  13. PHP Constants
  14. PHP If..Elseif..Else Conditional Statements
  15. PHP Switch..Case Conditional Statements
  16. PHP For and Foreach Loop Statements
  17. PHP While and Do While Statements
  18. PHP Functions
  19. PHP Class and Objects
  20. PHP Date and Time Operations

We have almost learned the variables and related types. But just variables do not enough to create useful applications. We generally need to operate over these variables and data. Operators are a way to operate on variable and data. For example if we need to sum two integer variables we should use sum operator. Let’s start looking available operators. We groups operators with the following group names.

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • Increment Operators
  • Logical Operators
  • String Operators
  • Array Operators

Arithmetic Operators

Arithmetic or Mathematical operations can be done with arithmetic operators. Here list of arithmetic operators.

+ Sum Operator

Sum operator is used to sum two variables or values. In this example $result will be 7.

– Subtract Operator

Subtract operator is used to subtract two variables or values. In this example $result will be 3 .

* Multiply Operator

Multiply operator is used to multiply two variables or values. In this example $result will be 10 .

/ Divide Operator

Divide operator is used to divide two variables or values. In this example $result will be 2.5 . The $result type will be a float number.

% Module Operator

Module operator is used to get remainder two variables or values. In this example $result will be 1 .

Assignment Operators

Assignment operators generally provide same functionality of Arithmetic operators with a bit different way. Assignment operators uses first value or variable to provide value and store result.

= Assign

Assignment will set variables value to the given.

+= Add and Assign

Add and assign operator will add left and right variables or values and set the result to the left variable. In this example $x will be 7 .

-= Subtract and Assign

Subtract and assign operator will subtract left and right variables or values and set the result to the left variable. In this example $x will be 3 .

LEARN MORE  How To Get Python String Length?

*= Multiply and Assign

Multiply and assign operator will multiply left and right variables or values and set the result to the left variable. In this example $x will be 10 .

/= Divide and Assign

Divide and assign operator will divide left and right variables or values and set the result to the left variable. In this example $x will be 7 .

%= Divide and Assign Modulus

Divide and assign operator will divide left and right variables or values and set the remainder to the left variable. In this example $x will be 7 .

Comparison Operators

Comparison operators generally used to compare two values or variables. These operators generally used to return some boolean result like true and false  and used generally with conditional keywords like if .

== Equal

Equal is used simply check whether given two values or variables are equal. If they are same this will return true if not this will return false.

=== Identical

Equal is used simply check whether given two values or variables are identical. If they are identical this will return true if not this will return false.

!= or <> Not Equal

Not equal is used simply check whether given two values or variables are not equal. If they are same this will return false if not this will return true.

!== Not Identical

Not identical is used simply check whether given two values or variables are identical. If they are identical this will return false if not this will return true.

< Less Than

Less than is used simply check whether first variables or values is lesser than second one.  If first variables is lesser than second one this will return true if not false.

LEARN MORE  C Constants and Define Preprocessor

> Greater Than

Greater than is used simply check whether first variables or values is greater than second one.  If first variables is greater than second one this will return true if not false.

>= Greater Than Or Equal To

Greater than  or equal to is used simply check whether first variables or values is greater or equal to than second one.  If first variables is greater or equal to than second one this will return true if not false.

<= Less Than or Equal To

Less than  or equal to is used simply check whether first variables or values is less or equal to than second one.  If first variables is less or equal to than second one this will return true if not false.

Increment Operators

Increment operators generally used as mathematical operations.

++$x Pre-increment

We can use pre-increment operator to increment single step the variable value before using this variable. In this example $x before  value is 6 and after value is 6 .

$x++ Post-increment

We can use post-increment operator to increment single step the variable value after using this variable. In this example $x before  value is 5 and after value is 6 .

–$x Pre-decrement

We can use pre-decrement operator to decrement single step the variable value before using this variable. In this example $x before  value is 4 and after value is 4 .

$x– Post-decrement

We can use post-decrement operator to decrement single step the variable value after using this variable. In this example $x before  value is 5 and after value is 64.

Logical Operators

Local operators generally used with boolean values and variables.

LEARN MORE  Powershell Trim Operation Like Filename, String, End, Start, Spaces

and , && Operator

and operator is used like below. If two values or variables are true this will return true if not it will return false. && can be used as and operator too.

or , || Operator

or operator is used like below. If two values or variables are false this will return false if not it will return true. || can be used as and operator too.

xor  Operator

xor operator is used like below. If two values or variables are same boolean value this will return true if not will return false.

! Not Operator

Not operator simply return the reverse boolean value of the given variable or value. If given variable of value is true result will be false. If the given value is false result will be true.

String Operators

String operators mainly used to concatenate given string variables or values.

. Concatenate

We can concatenate two string variable of value with . like below. In this example we will concatenate two string variable named $a and $b and result will be assigned to the $result .

.= Append

We can concatenate two string variable of value with . like below. In this example we will concatenate two string variable named $a and $b and result will be assigned to the $a .

PHP Tutorial Topics

  1. Introduction To PHP
  2. Installing PHP To Linux
  3. Installing PHP To Windows
  4. PHP Hello World Project with Eclipse
  5. PHP Syntax
  6. PHP Variables and Types
  7. PHP String Types
  8. PHP Numeric Type (Integer, Float, Double)
  9. PHP Boolean Type
  10. PHP Arrays
  11. PHP Operators
  12. PHP Ternary Operators
  13. PHP Constants
  14. PHP If..Elseif..Else Conditional Statements
  15. PHP Switch..Case Conditional Statements
  16. PHP For and Foreach Loop Statements
  17. PHP While and Do While Statements
  18. PHP Functions
  19. PHP Class and Objects
  20. PHP Date and Time Operations
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/php-operators/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.