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
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- 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...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: