PHP Operators PHP

An operator is a symbol that tells PHP to perform a mathematical or logical operation. Some operators expect two arguments, some only one. Most operators fall into three categories: arithmetic, logical, and bitwise. There are some exceptions, however.

Arithmetic-OperatorsArithmetic-Operators

Addition, subtraction, multiplication, and division are familiar concepts. They may be applied to integers or doubles. Using a string with an arithmetic operator causes the string to be converted to a number first. Modulo division returns the integer remainder of a division. The - operator may also be used to swap the sign on a number or variable. The increment and decrement operators are shorthand for adding or subtracting 1 from a ariable. You might remember that we used it. You may put an increment or decrement operator before or after a variable. If the variable is within an expression, you will get one of two behaviors. If an increment operator precedes the variable, the variable will be incremented prior to evaluation of the expression; otherwise the variable isn't operated on until after the value of the expression is computed.

Comparing Preincrement to Postincrement

<?
$VisitorsToday = 1;
// prints 1
print($VisitorsToday++);
// VisitorsToday is now 2
print("<BR>n");
// prints 3
print(++$VisitorsToday);

print("<BR>n");

In this first print statement VisitorsToday still contains the value 1 when it is printed, because the increment operator isn't applied until after the expression is evaluated. In the third print statement VisitorsToday is incremented before the expression is evaluated; therefore 3 is sent to the browser.


Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

PHP Topics