PHP Tutorials

111. Booleans in PHP

By: Andi, Stig and Derick : 2008-11-22

Description: Booleans were introduced for the first time in PHP 4 and didn't exist in prior versions. A Boolean value can be either true or false. PHP automatically converts types when needed. Boolean is probably the type that other types are most often converted to behind the scenes. This is because, in any conditional code such as if statements, loops, and so on, types are converted to this scalar type to check if the condition is satisfied. Also, comparison operators result in a Boolean value.


112. Traversing Arrays Using foreach in PHP

By: Andi, Stig and Derick : 2008-11-22

Description: There are a few different ways of iterating over an array. The most elegant way is the foreach() loop construct. The general syntax of this loop is foreach($array as [$key =>] [&] $value)


113. Traversing Arrays Using list() and each() in PHP

By: Andi, Stig and Derick : 2008-11-22

Description: Although foreach() is the nicer way of iterating over an array, an additional way of traversing an array is by using a combination of the list() construct and the each() function:


114. Using list() in PHP

By: Andi, Stig and Derick : 2008-11-22

Description: The list() construct is a way of assigning multiple array offsets to multiple variables in one statement:


115. Constants in PHP

By: Andi, Stig and Derick : 2008-11-22

Description: In PHP, you can define names, called constants, for simple values. As the name implies, you cannot change these constants once they represent a certain value. The names for constants have the same rules as PHP variables except that they don't have the leading dollar sign. It is common practice in many programming languages - including PHP - to use uppercase letters for constant names, although you don't have to. If you wish, which we do not recommend, you may define your constants as case-insensitive, thus not requiring code to use the correct casing when referring to your constants.


116. Binary Operators in PHP

By: Andi, Stig and Derick : 2008-11-22

Description: All the binary operators (except for the concatenation operator) work only on numeric operands. If one or both of the operands are strings, Booleans, nulls, or resources, they are automatically converted to their numeric equivalents before the calculation is performed.


117. Assignment operators in PHP

By: Andi, Stig and Derick : 2008-11-22

Description: Assignment operators enable you to write a value to a variable. The first operand (the one on the left of the assignment operator or l value) must be a variable. The value of an assignment is the final value assigned to the variable; for example, the expression $var = 5 has the value 5 (and assigns 5 to $var).


118. Comparison operators in PHP

By: Andi, Stig and Derick : 2008-11-22

Description: Comparison operators enable you to determine the relationship between two operands.


119. if Statements in PHP

By: Andi, Stig and Derick : 2008-11-22

Description: if statements are the most common conditional constructs, and they exist in most programming languages. The expression in the if statement is referred to as the truth expression. If the truth expression evaluates to true, the statement or statement list following it are executed; otherwise, they're not.


120. switch Statements in PHP

By: Andi, Stig and Derick : 2008-11-22

Description: You can use the switch construct to elegantly replace certain lengthy if/ elseif constructs. It is given an expression and compares it to all possible case expressions listed in its body. When there's a successful match, the following code is executed, ignoring any further case lines (execution does not stop when the next case is reached). The match is done internally using the regular equality operator (==), not the identical operator (===). You can use the break statement to end execution and skip to the code following the switch construct.