> Arithmetic Operators in php ~ Online tutorial

Arithmetic Operators in php

Using Arithmetic Operators
To perform mathematical operations on variables, use the standard arithmetic
operators, as illustrated in the following example:

<?php

// define variables

$num1 = 101;

$num2 = 5;

// add

$sum = $num1 + $num2;

// subtract

$diff = $num1 - $num2;

// multiply

$product = $num1 * $num2;
// divide

$quotient = $num1 / $num2;

// modulus

$remainder = $num1 % $num2;

?>



To perform an arithmetic operation simultaneously with an assignment, use the

two operators together. The following two code snippets are equivalent:


<?php

$a = $a + 10;

?>

<?php

$a += 10;

?>


Operator What It Does
= Assignment
+ Addition
- Subtraction
* Multiplication
/ Division; returns quotient
% Division; returns modulus
&& Logical AND
|| Logical OR
xor Logical XOR
! Logical NOT
++ Addition by 1

Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: