Cazpa.com PHP Developer & Website Designer

7Nov/090

PHP Operators (Basic PHP Operators)

Now that we have the variables lets do some maths using operators, operators are the symbols that connect all the variables together.

Simple maths with PHP:

<?php
// Define variables
$number1 = 123;
$number2 = 2;

// Add
$total1 = $number1 + $number2;

// Subtract
$total2 = $number1 - $number2;

// Multiply
$total3 = $number1 * $number2;

// Divide
$total4 = $number1 / $number2;

// Modulus
$total5 = $number1 % $number2;
?>

Now lets use auto-increment and auto-decrement operators

Auto-increment

<?php
// Define variable
$total = 123;

// increment it
$total++;
// $total is now 124

// This is the same as
$total = $total + 1;
?>

Auto-decrement

<?php
// Define variable
$total = 123;

// decrement it
$total--;
// $total is now 122

// This is the same as
$total = $total - 1;
?>

About Daniel Smith

I am the boss around here, if you need anything then send me a message :))

Popular Content & Keywords

rails vs php performance,php define variable,warning: mail() [function mail]: smtp server response: 554 the message was rejected because it contains prohibited virus or spam content in,add update delete in php,php tutorial // user registration w/ sql,warning: mail() [function mail]: smtp server response: 554 the message was rejected because it contains prohibited virus or spam content,ruby on rails vs php,facebook jsonwrapper,warning: mail() [function mail]: smtp server response: 554 the message was rejected because it contains prohibited virus or spam content in on line 15 error,twitter api php tutorial,php define href with variables,ruby on rails vs php 2010,adding records to a mysql database using php,facebook jsonwrapper php,php define head
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

You must be logged in to post a comment.

No trackbacks yet.

Powered by WordPress Lab