Etiqueta: PHP

for loops on PHP

for loops are the most complex loops in PHP. They behave like their C counterparts. The syntax of a for loop is: for (expr1; expr2; expr3) statement The first expression (expr1) is evaluated (executed) once unconditionally at the beginning of the loop. In the beginning of each iteration, expr2 is evaluated. If it evaluates to

Continuar leyendo...

do-while for PHP

do-while loops are very similar to while loops, except the truth expression is checked at the end of each iteration instead of in the beginning. The main difference from regular while loops is that the first iteration of a do-while loop is guaranteed to run (the truth expression is only checked at the end of

Continuar leyendo...

while operator

while loops are the simplest type of loop in PHP. They behave just like their C counterparts. The basic form of a while statement is: while (expr) statement The meaning of a while statement is simple. It tells PHP to execute the nested statement(s) repeatedly, as long as the while expression evaluates to TRUE. The

Continuar leyendo...

Alternative syntax for control structures

PHP offers an alternative syntax for some of its control structures; namely, if, while, for, foreach, and switch. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively. <?php if ($a == 5):

Continuar leyendo...

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

Continuar leyendo...

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

Continuar leyendo...

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

Continuar leyendo...

Array Operators

<- Scroll Horizontal disponible en esta tabla -> 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

Continuar leyendo...

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 =

Continuar leyendo...