PHP Operators

PHP Operators
In this tutorial we will discuss the PHP operators and how they are used. There are five types of PHP operators; the assignment, arithmetic, comparison, logical and increment/decrement operators.
  • Assignment Operators
    The assignment operators are used to assign a value to a PHP variable. For example I might want to assign the value of Diane to a variable named $MyName. There are four assignment operators.

    = This assigns a value to the variable named $no

    $no = 1;
    += This assigns the value of $no +1 to the variable named $no

    $no += 1;
    – = This assigns the value of $no -1 to the variable named $no

    $no – = 1;
    .= This concatenates (adds to) two values together. In the example below I am adding the value of " Cipollo" to the $MyName variable. Remember that the value of $MyName is Diane.

    $MyName .= " Cipollo";

    Now the value of $MyName is Diane Cipollo.


  • Arithmetic Operators
    There are five PHP arithmetic operators. But don't panic. It's just basic math.

    + addition

    This adds two values together.

    $c = $a + $b;
    subtraction

    This subtracts one value from another value.

    $c = $a - $b;
    * multiplication

    This multiplies two values.

    $c = $a * $b;
    / division

    This divides two values.

    $c = $a / $b;
    % modulus or remainder

    This gives the remainder of two values.

    $c = $a % $b;

    Let's say the value of $a is 7 and the value of $b is 5. Then the value of $c would be the remainder which is 2.
Next →






This site needs an editor - click to learn more!



RSS
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map





Content copyright © 2023 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.