CopyPastehas never been so tasty!

Arithmetic Operators (Add, Subtract, Multiply, Divide) in PH

by anonymous

  • 0
  • 0
  • 0

Orignal Source:

Arithmetic Operators in PHP:


Operators are used in php on variables. We apply operators on all type of variables like int, float, double etc.


 The plus operator (+) is used to add two or more $variables values. The subtraction operator (-) is used to subtract two or more $variables values. The Multiplication operator (*) is used to multiply two or more $variables values. The Mod operator (%) is used to get Mod two or more $variables values. An increment operator is used to increasing the variable value. A decrement operator is used to decreasing variable value.





$addition_of_var = 40+50;

$addtion_of_string_var=" Tahreem"."Anwar"."Learnig"."PHP";

$subtraction = 55.790 - 34.555;

$multiplication =  99* 40;

$mod_of_vars = 89 % 2;

$increment = 8; $increment = ++$increment;

$decrement = 9;  $decrement = --$decrement;


echo $result1 = "addition_of_var:$addition_of_var <br>";

echo $result2 = " addtion_of_string_var: $addtion_of_string_var <br>";

echo $result3 = "subtraction:$subtraction       <br>";

echo $result4 = "multiplication:$multiplication       <br>";

echo $result5= "mod_of_vars:$mod_of_vars       <br>";

echo $result6 = "increment:$increment       <br>";

echo $result7 = "decrement:$decrement      <br>";





addtion_of_string_var: TahreemAnwarLearnigPHP 



On line 2 we have added two variables. On line 3 we have added three strings means concatenate them or combine them with (.) dot operator. On line 4 we apply subtraction operator (-) on floating point variables. On line 5 we multiply two numbers. On line 6 we get mode of two numbers. On line 7 we increment variable so the value in output will be 8 incremented by 1. On line 8 we decrement variable so the value is decrease by 1.

Add A Comment: