PHP Operators : Using Arithmetic Operators

Using Arithmetic Operators in PHP you can perform mathematical operations on PHP variables. refer to the example below.

Using PHP Arithmetic Operator

//define variables
<?php

$num1 = 50;
$num2 = 30;

//Addition
$sum = $num1 + $num2;

//Subtraction
$difference = $num1 - $num2;

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

//Division
$quotient = $num1 / $num2;

//Modulus
$remainder = $num1 % $num2;

?>

you may also use the shorthand using the PHP Assignment Operator and Arithmetic Operator together.

PHP Assignment Operator and Arithmetic Operator Together

//define variables

< ?php

$num1 = 50;
$num2 = 30;

//Addition
$num1 = $num1+ $num2;
//Shorthand for this is..
$num1+=$num2;

//Subtraction
$num1 = $num1 - $num2;
//Shorthand for this is..
$num1-=$num2;

//Multiplication
$num1 = $num1 * $num2;
//Shorthand for this is..
$num1 *=$num2;

//Division
$num1 = $num1 / $num2;
//Shorthand for this is..
$num1 /=$num2;

//Modulus
$num1= $num1 % $num2;
//Shorthand for this is..
$num1%=$num2;

?>
Share and Bookmark this Post..

  • Digg
  • Yahoo! Buzz
  • Twitter
  • Facebook
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Technorati
  • Reddit
  • Sphinn
  • MySpace
  • Slashdot
  • BlinkList
  • Live
  • Mixx
  • NewsVine
  • Yahoo! Bookmarks
  • Ratimarks
  • LinkedIn





Tags: ,

Leave a Reply

This blog will make your link do follow after you leave 5 comments. i check every comment posted and reply to each also. please do not spam i hate spam, there is no room for spam here in my blog thanks!

CommentLuv Enabled
:argh: :| :$ :B :cool: :*( :curious: x_x :gasp: =D :happy: :/ :D :injured: :lol: :lol2: :love: :X :meh: O_o :ohhyeahh: D: :omg: :raisebrow: :P :( 0_0 :shocked: :sly: :) :] ;] :worry: :wow:

Subscribe to feed

this blog use Comment Luv

Featured Post


Make your Wordpress URL Search Engine Friendly
Simple steps to make your wordpress url search engine friendly..


Give some luv with comment luv
This blog is now comment luv powered..


Fix Wordpress PHP fatal error memory size exhauster
Ways on how to solve PHP fatal error or PHP memory limit on wordpress blogs anr other opensource web apps..


Download Norton Antivirus Internet Security for free
Read this post to know how you can download a free norton antivirus or internet security..


Sponsored Links


 6 Users Online