PHP also having operators like other programming Languages like Java, C++, and C etc.

PHP operators are:-

  • Assignment Operators.
  • Arithmetic’s Operators.
  • Comparison Operators.
  • String Operators.

Assignment Operators:

PHP having assignment operators i.e. (=) 

Example:

$a= 4;
$b = $a;

Arithmetic’s Operators:

PHP Arithmetic’s Operators are: +,-,*,/,%.

Example:

$a=10;
$b=20;
$c=$a+$b; (addition of two variables)
$d=$a-$b; (Subtraction of two variables)
$d=$a*$b; (Multiplication of two variables)
$d=$a/$b; (Division of two variables)
$d=$a%$b;

 

Comparison Operators:

PHP Comparison Operators are: ==, != , , =.

Example:

$a==$b; (Comparison of two variables)
$a! =$b; (addition of two variables)
$a<$b;
$a>$b;
$a<=$b;
$a>=$b;

String Operators:

PHP Strings Operators are: 

There are generally tow String Operators in PHP

  • First is a concatenation Operators (‘.’).
  • The Second one is Assignment Operators (‘=’)

Example:     

PHP Conditional Statements

PHP Conditional operators are:

  • IF Statement.
  • IF..ElSE Statement.
  • IF..ELSEIF….Statement
  • Switch Statement. 

IF Statement: Like other programming language IF statement executes some statement when some particular condition is true.

Syntax: If (condition)

Code Execute;

Example:

IF..Else Statement: IF statement is true then execute one statement otherwise execute second statement.

Syntax:

IF (condition)
Code1 Execute;
Else
Code2 Execute; 

Example:

IF..ELSEIF….Statement : If some condition is true then execute one statement else if some another statement then execute another statement. It is particularly an if else ladder.

Syntax:

if(condition)
Code1 Execute;
elseIf
Code2 Execute; 

Example:

Switch Statement: To overcome the multiple If-Else statement problems we used switch statement. It is conditional statement are used to perform different action based on different conditions.

Working of Switch Statement: It takes one variable as input and checks it against all the different cases you set for the switch statements.

Syntax:

Switch (n)
{
            Case Lable1:
            Code to be executed when n=lable1;
            Break;
            Case Lable2:
            Code to be executed when n=lable2;
            Break;
            Case Lable3:
            Code to be executed when n=lable3;
            Break;
            Default:
            Condition fail;
            Break;
}

Like it on Facebook, Tweet it or share this article on other bookmarking websites.

No comments