Wednesday, May 29, 2019

PHP Different Operators !!

PHP Different Operators !!



PHP Operators 


Operators are used for perform different kinds of operation on values.

We can do different operation using operators on different values.

There are operators we can use in PHP


Arithmetic Operators


Arithmetic operators are used to perform simple mathematical operations like addition, subtraction, multiply, division and modulo.

operator syntax operation
+ $a + $b addition of operands
- $a - $b subtraction of operands
* $a * $b multiplication of operands
/ $a / $b division of operands
% $a % $b reminder of operands

Program :

<?php

     $x= 10      $y= 3 
      echo "The sum is : ". ($x+$y) 
      echo "The difference is : ". ($x-$y)
      echo "Multiplication is : ". ($x*$y)
      echo "Division is : ". ($x/$y)
      echo "Modulus is : " . ($x%$y)
?>

Output :


The sum is : 13
The difference is : 7
Multiplication is : 30
Division is : 3.333333
Modulus is : 1


Logical Operators


This operators are used in conditional statements.it is used to check true or false conditions.

Operators is used like logical and, logical or, logical not, and, or, xor.

operator syntax operation
&& $a && $b true if both operands are true otherwise false
|| $a || $b true if either one of both operands are true otherwise false
! !$b true if $b false
and $a and $b true if both operands are true otherwise false
or $a or $b true if either one of both operands are true otherwise false
xor $a xor $b false if both operands are true otherwise true

Program :

<?php
$name=”Nibkarma”;$pass=”123”;
if($name==”NibKarma” && $pass==”123”){echo “Welcome to Nibkarma”;}else{echo “Invalid username or Password”;}
?>


Output :

Welcome to NibKarma


Comparison Operators


Comparison operators are used to compare the variables.

It returns the Boolean value either true or false.

Operators like <, >, <=, >=, ==, != is used.

operator syntax operation
> $a > $b true if a is greater then b
>= $a >= $b true if a is greater then or equal to b
< $a < $b true if a is less then b
<= $a <= $b true if a is less then or equal to b
== $a == $b true if both operands are same
!= $a != $b true if a is not equal to b

Program :


<?php
$a =5;$b =7;
if($a==$b){echo “Equal”;}else{echo “Not Equal”}
?>


Output :


Not Equal


Assignment Operators


Assignment operation used to assign value to the operator without do extra operations.

Operators like =, +=, -=, *=, /=, %= is used.

operator syntax operation
= $a = $b true if a is equal to b
+= $a += $b addition as $a = $a + $b
-= $a -= $b subtraction as $a = $a - $b
*= $a *= $b multiplication as $a = $a * $b
/= $a /= $b division as $a = $a / $b
%= $a %= $b modulo as $a = $a % $b

Program :


<?php 

$a=12;$b=$a;

echo $b; echo "<br>";

$a+=$b;echo $a;echo "<br>";

$a-=$b;echo $a;echo "<br>";

$a*=$b;echo $a; echo "<br>";

$a/=$b;echo $a;echo "<br>";

$a%=$b;echo $a;echo "<br>";

$a.=$b;echo $a;
?> 


Output :

122412144120012


Increment/Decrement Operators


This operators are used for increment or decrement the value of operators.

++ and -- operators are used.

operator syntax operation
++ ++$a pre-increment : first increment then prints
++ $a++ post-increment : first print then increment
-- --$a pre-decrement : first decrement then print
-- $a-- post-decrement : first print then decrement


Program :

<?php
$a=12;$b=++$a;echo "a=".$a." ,b=".$b; //prints a=13 ,b=13echo "<br>";
$b=$a++;echo "a=".$a." ,b=".$b; //prints a=14 ,b=13echo "<br>";
$b=--$a;echo "a=".$a." ,b=".$b; //prints a=13 ,b=13echo "<br>";
$b=$a--;echo "a=".$a." ,b=".$b; //prints a=12 ,b=13echo "<br>";
?>
 
Output :

a=13 ,b=13a=14 ,b=13a=13 ,b=13a=12 ,b=13


String Operators


String operators are used for string concatenation and assign value to string.

' . ' and '.= ' operators are used.

operator syntax operation
. $a.$b concatenated $a and $b
.= $a.=$b It concatenated and then assign as $a = $a.$b

Conditional And Ternary Operators


Conditional Operators are used to compare the values.

It works as a if-else statement.

Ternary operator is ?: 

Syntax :

$var = (condition)? $a : $b ;





Mesothelioma Survival Rates , Mesothelioma Attorneys California , Seattle Mesothelioma Lawyer , Mesothelioma Suit , Mesothelioma Claim , Wisconsin Mesothelioma Attorney , Mesothelioma Attorney illinois , Mesothelioma Trial Attorney ,Houston Mesothelioma Attorney , Mesothelioma Lawyer Dallas , New York Mesothelioma Law Firm,Mesothelioma Lawyer Asbestos Cancer Lawsuit , Mesothelioma Lawyers San Diego,Mesothelioma Litigation , Mesothelioma Attorney Assistance , Mesothelioma Lawyer Asbestos Cancer Lawsuit , Mesothelioma Lawyer Chicago , New York Mesothelioma Law Firm , 


Houston Mesothelioma Attorney , Mesothelioma Lawyer Dallas , Mesothelioma Care , Mesothelioma Trial Attorney , Mesothelioma Lawyer Texas , Lawsuit Mesothelioma  , Truck Accident Attorney Los Angeles ,Asbestos Exposure Lawyers  , Mesothelioma Cases  , Emergency Response Plan ppt , Mesothelioma Lawyers San Diego  , Asbestos Mesothelioma Lawsuit  , Tennessee Mesothelioma Lawyer , Meso Lawyer  , Mesothelioma Settlements Amounts  , Mesothelioma Law Firms , New Mexico Mesothelioma Lawyer , Accident Attorneys Orange County , Mesothelioma Lawsuit ,Personal Injury Accident Lawyer  , Purchase Structured Settlements  , Firm Law Mesothelioma , Car Accident Lawyers Los Angeles , Mesothelioma Attorneys , Structured Settlement Company  , Auto Accident Lawyer San Francisco  , Mesotheolima  , Los Angeles Motorcycle Accident Lawyer


Mesothelioma , Mesothelioma Lawyer Virginia , Seattle Mesothelioma Lawyer , Mesothelioma Attorney illinois , Mesothelioma Drug , Mesothelioma Attorney DirectoryMesothelioma Settlements , Mesothelioma Help  , Mesothelioma ct , Mesothelioma Attorney Florida , Washington Mesothelioma Attorney , Best Mesothelioma Lawyers , Diagnosed With Mesothelioma , Mesothelioma Settlement Amounts , Mesothelioma Personal Injury Lawyers , Mesothelioma Compensation , Attorney Lawyer Mesothelioma  ,Colorado Mesothelioma Lawyers,Mesothelioma Lawsuits , Mesothelioma Claims , Average Mesothelioma Settlement , Average Mesothelioma Settlement , Mesothelioma Law Suit , Alabama Mesothelioma Lawyer , alabama Mesothelioma Lawyer , utah mesothelioma lawyer , Dallas Mesothelioma Lawyer , Mesothelioma Attorney California , Mesothelioma Lawyer California ,Mesothelioma Survival Rates ,

Mesothelioma Attorneys California, Wisconsin Mesothelioma Attorney Mesotheliama , Mesothelioma Lawyer Virginia , Seattle Mesothelioma Lawyer , Mesothelioma Attorney illinois, Mesothelioma Trial Attorney Injury Lawyer Houston tx , Baltimore Mesothelioma Attorneys , Mesothelioma Care ,Mesothelioma Trial Attorney ,Mesothelioma Lawyer Texas , Mesothelioma Lawyer Dallas , Mesothelioma Care , Mesothelioma Trial Attorney , Mesothelioma Lawyer Texas , California Mesothelioma Attorney Philadelphia Mesothelioma Lawyer , Illinois Mesothelioma Lawyer , Mesothelioma Attorney , Mesothelioma Claims , Average Mesothelioma Settlement 
Integrated ehr , Mesothelioma Law Sui , Mesothelioma Lawyer California,Mesothelioma Attorney California ,Mesothelioma Law Suits ,Dallas Mesothelioma Attorneys ,Mesothelioma Drug ,Mesothelioma Attorney Directory