elseif/else if

elseif, as its name suggests, is a combination of if and else. Like else, it extends an if statement to execute a different statement in case the original if expression evaluates to FALSE. However, unlike else, it will execute that alternative expression only if the elseif conditional expression evaluates to TRUE. For example, the following […]

else operator

Often you’d want to execute a statement if a certain condition is met, and a different statement if the condition is not met. This is what else is for. else extends an if statement to execute a statement in case the expression in the if statement evaluates to FALSE. For example, the following code would […]

if operator

The if construct is one of the most important features of many languages, PHP included. It allows for conditional execution of code fragments. PHP features an if structure that is similar to that of C: if (expr) statement As described in the section about expressions, expression is evaluated to its Boolean value. If expression evaluates […]

Type Operators

instanceof is used to determine whether a PHP variable is an instantiated object of a certain class: Example #1 Using instanceof with classes <?php class MyClass { } class NotMyClass { } $a = new MyClass; var_dump($a instanceof MyClass); var_dump($a instanceof NotMyClass); ?> The above example will output: bool(true) bool(false) instanceof can also be used […]

Array Operators

Array Operators Example Name Result $a + $b Union Union of $a and $b. $a == $b Equality TRUE if $a and $b have the same key/value pairs. $a === $b Identity TRUE if $a and $b have the same key/value pairs in the same order and of the same types. $a != $b Inequality […]

String Operators

There are two string operators. The first is the concatenation operator (‘.’), which returns the concatenation of its right and left arguments. The second is the concatenating assignment operator (‘.=‘), which appends the argument on the right side to the argument on the left side. Please read Assignment Operators for more information. <?php $a = […]

Execution Operators

PHP supports one execution operator: backticks («). Note that these are not single-quotes! PHP will attempt to execute the contents of the backticks as a shell command; the output will be returned (i.e., it won’t simply be dumped to output; it can be assigned to a variable). Use of the backtick operator is identical to […]

Error Control Operators

PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored. If the track_errors feature is enabled, any error message generated by the expression will be saved in the variable $php_errormsg. This variable will be overwritten […]

Comparison Operators

Comparison operators, as their name implies, allow you to compare two values. You may also be interested in viewing the type comparison tables, as they show examples of various type related comparisons. Comparison Operators Example Name Result $a == $b Equal TRUE if $a is equal to $b after type juggling. $a === $b Identical […]

Bitwise operators

Bitwise operators allow evaluation and manipulation of specific bits within an integer. Bitwise Operators Example Name Result $a & $b And Bits that are set in both $a and $b are set. $a | $b Or (inclusive or) Bits that are set in either $a or $b are set. $a ^ $b Xor (exclusive or) […]