Assignment Operators on PHP

The basic assignment operator is «=». Your first inclination might be to think of this as «equal to». Don’t. It really means that the left operand gets set to the value of the expression on the rights (that is, «gets set to»). The value of an assignment expression is the value assigned. That is, the […]

Arithmetic Operators on PHP

Remember basic arithmetic from school? These work just like those. Arithmetic Operators Example Name Result -$a Negation Opposite of $a. $a + $b Addition Sum of $a and $b. $a – $b Subtraction Difference of $a and $b. $a * $b Multiplication Product of $a and $b. $a / $b Division Quotient of $a and […]

Operator Precedence on PHP

The precedence of an operator specifies how «tightly» it binds two expressions together. For example, in the expression 1 + 5 * 3, the answer is 16 and not 18 because the multiplication («*») operator has a higher precedence than the addition («+») operator. Parentheses may be used to force precedence, if necessary. For instance: […]

Operators on PHP

Operator Precedence Arithmetic Operators Assignment Operators Bitwise Operators Comparison Operators Error Control Operators Execution Operators Incrementing/Decrementing Operators Logical Operators String Operators Array Operators Type Operators An operator is something that you feed with one or more values (or expressions, in programming jargon) which yields another value (so that the construction itself becomes an expression). So […]

Magic constants for PHP

PHP provides a large number of predefined constants to any script which it runs. Many of these constants, however, are created by various extensions, and will only be present when those extensions are available, either via dynamic loading or because they have been compiled in. There are seven magical constants that change depending on where […]

Expressions on PHP

Expressions are the most important building stones of PHP. In PHP, almost anything you write is an expression. The simplest yet most accurate way to define an expression is «anything that has a value». The most basic forms of expressions are constants and variables. When you type «$a = 5″, you’re assigning ‘5’ into $a. […]

Constants on PHP

A constant is an identifier (name) for a simple value. As the name suggests, that value cannot change during the execution of the script (except for magic constants, which aren’t actually constants). A constant is case-sensitive by default. By convention, constant identifiers are always uppercase. The name of a constant follows the same rules as […]

Variables From External Sources

When a form is submitted to a PHP script, the information from that form is automatically made available to the script. There are many ways to access this information, for example: Example #1 A simple HTML form <form action=»foo.php» method=»post»> Name: <input type=»text» name=»username» /><br /> Email: <input type=»text» name=»email» /><br /> <input type=»submit» name=»submit» […]

Variable variables on PHP

Sometimes it is convenient to be able to have variable variable names. That is, a variable name which can be set and used dynamically. A normal variable is set with a statement such as: <?php $a = ‘hello’; ?> A variable variable takes the value of a variable and treats that as the name of […]

Variable scope on PHP

The scope of a variable is the context within which it is defined. For the most part all PHP variables only have a single scope. This single scope spans included and required files as well. For example: <?php $a = 1; include ‘b.inc’; ?> Here the $a variable will be available within the included b.inc […]