Home arrow PHP arrow Page 3 - PHP Operators

Arithmetic Operators - PHP

What can you do without operators? Not much, if you're trying to do without them in a programming language, and PHP is no exception. On Monday, we barely had time to show you a long list of the operators in PHP. Today, we're going to show you what they do.

TABLE OF CONTENTS:
  1. PHP Operators
  2. Assignment Operators
  3. Arithmetic Operators
  4. Incremental Operators
  5. Better by Comparison
  6. Logical Operators
By: James Payne
Rating: starstarstarstarstar / 20
October 31, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

You have been using most of the arithmetic operators since childhood. That and your fingers and toes. But don't worry; PHP is smarter than you. It's prettier than you. And according to some of the other programming languages, it really gets around. ASP is really jealous, but don't tell it I said so.

Let's look at some examples.


<html>

<body>


<?php


$add = 1 + 0;

$subtract = 2 - 1;

$multiply = 1 * 1;

$division = 2 / 2;

$modulus = 5 % 2;


echo $add;

echo $subtract;

echo $multiply;

echo $division;

echo $modulus;


?>


</body>

</html>

The above code would print out all the values of our variables:


  1

  1

  1

  1

  1

A Brief Note About My Dear Friend...The Modulus

The majority of the tutorials I've read on PHP never really explained Modulus in simple terms and so I never knew what it did. Maybe I'm just an idiot. But if there are other idiots out there, then you are in luck, because I am going to put this in very simple terms. Modulus gives you the remainder in division. Period. If I divide 2 / 2, there is no remainder. If I divide 3 /7 there is a remainder of 1. Modulus would return that 1.



 
 
>>> More PHP Articles          >>> More By James Payne
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap

Dev Shed Tutorial Topics: