Home
XHTML
CSS
PHP
MySQL
SEO
JavaScript
Computer Basics
Number Systems
LINUX


PHP Operators

PHP | Values | Operators | Functions | Arrays | Forms | Sessions-Cookies | Classes

Operators are symbols that modify values. The  .  concatenation operator connects strings and variables in sequence. This is an alternative method to quotes within quotes management and multiple echo statements. The concatenation operator is different than a period used in a string...

<?php

$name='tree';
$age=100;

echo 'I am a ' . $name . ' and I am ' . $age . ' years old.';

?>

The output is...

I am a tree and I am 100 years old.




Double quotes allow variable substitution...

<?php

$name='tree';
$age=100;

echo "I am a $name and I am $age years old.";

?>

The output is...

I am a tree and I am 100 years old.



These are arithmetic operators...

add
subtract
multiply
divide
remainder
++  increment
--  decrement



Operators can be combined. An operator followed with the  =  means to apply that operator to the variable...

<?php

$number=6;
$number+=9;

echo $number;

?>

The output is...

15



This is another example of combining operators...

<?php

$text='A bird, or two, ';
$text.='or three, or four.';

echo $text;

?>

The output is...

A bird, or two, or three, or four.




The  ++  increment operator increases one numeric value...

<?php

$number=9;
$number++;

echo $number;

?>

The output is...

10




The  --  decrement operator decreases one numeric value. This example combines the operator and variable...

<?php

$number=12;

echo --$number;

?>

The output is...

11




An evaluation within  ( )  parenthesis takes precedence in a statement...

<?php

echo (3 + 6) * 9;

?>

The output is...

81



These are comparison operators...

<=  less than or equal to
>=  greater than or equal to
!=  not equal to
==  equal to


These are logical operators...

&&  and
||  or
not




SEO Vancouver, Washington
SEO Portland, Oregon
Website Design Vancouver, Washington