PHPEveryday.com PHP and Web Development Tutorial
What are you looking for?


PHP Operators: Arithmetic Operators


PHP Operators Step By Step Tutorial - Part 2: Arithmetic Operators is operator that is used to conduct mathematical calculation.

Arithmetic Operators Table

Operator Info Example
+ Addition $p = 30 + 40 //$p = 70
- Reduction $q = 4 - 1 //$q = 3
* Multiplication $r = 5 * 5 //$r = 25
/ Division $s = 36/6 //$s = 6
% Rest of to (modulo) $t = 9%8 //$t = 1

In the complex expression which is entangled of many operand, operator *, /, and % have the same priority but it is higher rather than operator + and -. For further information, just pay attention to the example as following:

$a = 20 + 4 % 4

4 % 4 will be done first, so that result is 21 not 6.

Pay attention to the example of using aritmatika operator at script as following :
File name : aritmatikaoperator.php

<html>
<head>
<title>Using Arithmetic Operators</title>
</head>

<body>
<?
print("Addition: <br>");
printf("9 + 7 = %d <br>", 9 + 7);
printf("9.5 + 7 = %f <br>", 9.5 + 7);
printf("9.5 + 7.5 = %f <br>", 9.5 + 7.5);
printf("-9.5 + 7.5 = %f <br>", -9.5 + 7.5);
print("Reduction: <br>");
printf("9 - 7 = %d <br>", 9 - 7);
printf("9.5 - 7 = %f <br>", 9.5 - 7);
printf("9.5 - 7.5 = %f <br>", 9.5 - 7.5);
printf("-9.5 - 7.5 = %f <br>", -9.5 - 7.5);
print("Multiplication: <br>");
printf("9 * 7 = %d <br>", 9 * 7);
printf("9.5 * 7 = %f <br>", 9.5 * 7);
printf("9.5 * 7.5 = %f <br>", 9.5 * 7.5);
printf("-9.5 * 7.5 = %f <br>", -9.5 * 7.5);
print("Division: <br>");
printf("9 / 7 = %d <br>", 9 / 7);
printf("9.5 / 7 = %f <br>", 9.5 / 7);
printf("9.5 / 7.5 = %f <br>", 9.5 / 7.5);
printf("-9.5 / 7.5 = %f <br>", -9.5 / 7.5);
print("Modulus: <br>");
print(" 9 % 7 = "); print(9 % 7 ."<br>");
print("9.5 % 7 = "); print(9.5 % 7 ."<br>");
print("9.5 % 7.5 = "); print( 9.5 % 7.5."<br>");
print("-9.5 % 7.5 = "); print( -9.5 % 7.5."<br>");
print("9.5 % -7.5 = "); print( 9.5 % -7.5."<br>");
print"<br>";
?>
</body>
</html>


Series this article:
PHP Operators: Introduction
PHP Operators: Arithmetic Operators
PHP Operators: Assignment Operators
PHP Operators: Assignment Operators Table
PHP Operators: Bitwise Operators
PHP Operators: Relation Operators
PHP Operators: Ternary Operator
PHP Operators: Error Control Operator
PHP Operators: Execution Operator
PHP Operators: Increment or Decrement Operator
php Operators: Logic Operator
PHP Operators: String Operator
PHP Operators: Array Operator
PHP Operators: Object Operator
PHP Operators: Operator Priority
PHP Constants: Introduction


Tag: operator, Arithmetic Operators Category: PHP Basic Post : March 08th 2008 Read: 1,531 Bookmark and Share

blog comments powered by Disqus


Database Tutorial
  • Learn PHP MySQL
  • Learn PHP ADOdb
  • Learn PHP Data Object/PDO
  • Learn PHP XML
  • Learn PHP SimpleXML
Security Tutorial
  • Learn PHP Security
  • Learn HTTP Authentication
  • Learn PHPSecureSite
Framework Tutorial
  • Learn CodeIgniter
  • Learn Joomla
  • Learn Smarty
  • Learn Zend Framework
Template Tutorial
  • Learn Joomla Template
  • Learn WordPress Template
API Tutorial
  • Learn Facebook
JS Framework Tutorial
  • Learn MooTools
  • Learn JQuery
AJAX Tutorial
  • Learn AJAX in 10 Minutes
  • Learn AJAX Client Side
  • Learn AJAX PHP
  • Learn AJAX Remote Server
  • Learn AJAX Repetitive
  • Learn AJAX MySQL
  • Learn AJAX Grid
Web Services Tutorial
  • Learn Web Services NuSOAP
  • Learn Web Services WSDL
  • Learn Web Services WSDL Array
  • Learn Web Services .NET Grid
  • Learn Web Services WDDX
Package Post
  • Joomla Intro
  • Joomla Component
  • Joomla Module
  • Joomla MVC
  • Joomla MVC Backend
  • PostNuke Intro
  • Zend Framework Intro
  • Zend Framework Action
  • Zend Framework Database
  • Zend Framework Registry
  • Zend Framework Config
  • Zend Framework Login
  • Zend Framework Session
  • PHP Array Tips
  • PHP File Tips
  • PHP Email
  • PHP Ms Excel
  • PHP Pattern
  • PHP SMS
  • Flash Database
  • PHP Multitier
  • jQuery Introduction
  • jQuery Selectors
  • Portable Web Server
  • Web Mobile Intro
  • Drupal Installation
  • Drupal Configuration