0 Comments
0 Shares
3K Views
0 Reviews
Directory
Discover new people, create new connections and make new friends
-
Please log in to like, share and comment!
-
PHP Nested if StatementNested If You can have if statements inside if statements, this is called nested if statements. ExampleGet your own PHP Server An if inside an if: $a = 13; if ($a > 10) { echo "Above 10"; if ($a > 20) { echo " and also above 20"; } else { echo " but not above 20"; } } Try it Yourself »0 Comments 0 Shares 3K Views 0 Reviews
-
PHP switch StatementThe switch statement is used to perform different actions based on different conditions. The PHP switch Statement Use the switch statement to select one of many blocks of code to be executed. Syntax switch (expression) { case label1: //code block break; case label2: //code block; break; case label3: //code block break;...0 Comments 0 Shares 3K Views 0 Reviews
-
PHP LoopsIn the following chapters you will learn how to repeat code by using loops in PHP. PHP Loops Often when you write code, you want the same block of code to run over and over again a certain number of times. So, instead of adding several almost equal code-lines in a script, we can use loops. Loops are used to execute the same block of code again and again, as long as a certain condition is...0 Comments 0 Shares 3K Views 0 Reviews
-
PHP while LoopThe while loop - Loops through a block of code as long as the specified condition is true. The PHP while Loop The while loop executes a block of code as long as the specified condition is true. ExampleGet your own PHP Server Print $i as long as $i is less than 6: $i = 1; while ($i < 6) { echo $i; $i++; } Try it Yourself »...0 Comments 0 Shares 3K Views 0 Reviews
-
PHP do while LoopThe do...while loop - Loops through a block of code once, and then repeats the loop as long as the specified condition is true. The PHP do...while Loop The do...while loop will always execute the block of code at least once, it will then check the condition, and repeat the loop while the specified condition is true. ExampleGet your own PHP Server...0 Comments 0 Shares 3K Views 0 Reviews
-
PHP for LoopThe for loop - Loops through a block of code a specified number of times. The PHP for Loop The for loop is used when you know how many times the script should run. Syntax for (expression1, expression2, expression3) { // code block } This is how it works: expression1 is evaluated once expression2 is evaluated before each iteration...0 Comments 0 Shares 3K Views 0 Reviews
-
PHP foreach LoopThe foreach loop - Loops through a block of code for each element in an array or each property in an object. The foreach Loop on Arrays The most common use of the foreach loop, is to loop through the items of an array. ExampleGet your own PHP Server Loop through the items of an indexed array: $colors = array("red", "green", "blue", "yellow"); foreach ($colors as...0 Comments 0 Shares 3K Views 0 Reviews
-
PHP BreakThe break statement can be used to jump out of different kind of loops. Break in For loop The break statement can be used to jump out of a for loop. ExampleGet your own PHP Server Jump out of the loop when $x is 4: for ($x = 0; $x < 10; $x++) { if ($x == 4) { break; } echo "The number is: $x <br>"; } Try it Yourself...0 Comments 0 Shares 4K Views 0 Reviews
-
PHP ContinueThe continue statement can be used to jump out of the current iteration of a loop, and continue with the next. Continue in For Loops The continue statement stops the current iteration in the for loop and continue with the next. ExampleGet your own PHP Server Move to next iteration if $x = 4: for ($x = 0; $x < 10; $x++) { if ($x == 4) {...0 Comments 0 Shares 3K Views 0 Reviews