Php Statement Examples Break Statement Breaking a Loop Using the break Statement Break 1 or break 2 The break command applies to both loops and switch/case statements break within a for loop Using break to avoid division by zero Continue Statement Using the continue Statement continue within a for loop Using continue instead of break Counting to 10 with do ... while Do while loop do while loop with counter do while with integer counter do...while loop is executed at least once Break in Nested Loops The do...while Statement Catching Exceptions in PHP 5 extends Exception to create your own exception Using PHP 5 exception handling Using Custom Exceptions to Handle Different Circumstances For statement without second condition For statement without all three statements For loopFor loopUse for loop to output HTML table For loop format If statement inside a for loop Nesting Two for Loops A for Loop That Divides 4000 by Ten Incremental Numbers Using the for Statement A division table A for loop in PHP Alternating table row colors with for() Loops Within Loops Iterating through a multidimensional array with for() Iterating through a numeric array with for() Loop goes from 0 to 100 in steps of 0.1 Fahrenheit and Celsius table by for loop Specifying a number after break, such as break 2, to break out of two loops or switch/case statements Multiple expressions in for() Printing a select menu with for() Printing out all the web-safe color codes Foreach Demo Looping through an Enumerated Array Array element order and foreach() Iterating through a multidimensional array with foreach() Modifying an array with foreach() Using foreach() to Iterate Through an Array Using foreach() with numeric arrays Displaying the contents of an array using a loop Iterating Through Object Properties Implementing the traversable Iterator Executing Multiple Statements with One if An if Statement That Uses else An if statement That Uses else and else if An if Statement for string Within an if Else statement In if statement use OR to connect two conditions Use and to connect two statement in if statement A helpful addition to if statements is the elseif statement, which allows you to chain conditions together in a more intelligent wayAn if Statement Basic Use of the if Statement Case Switching Checking multiple conditions Making a decision with if() Multiple statements in an if() code block If-else Statement Using if Statements to Mimic a select Statement Using if statement to print "Youth message" if $age is between 18 and 35 Using if to test for multiple values Multiconditional if Statements Using else with if() Using elseif() Print the string "Child message" if the $age variable is between 1 and 17 Use the 'default' case Omitting the break statement can be useful in some cases switch command for string value A switch Statement for string A switch Statement Using the DEFAULTUsing switch to test for multiple values Using the switch Statement In a switch/case block, you specify what you are checking against, then give a list of possible values you want to handle. Switch Statement Switch and constants Using endswitch to end the switch definition What happens when there are no break keywords Throwing an Exception A sample while loop that counts to 10 A while Statement Approximating a square root Convert the while statement into a for statement? Create a while statement that prints every odd number between 1 and 49 while and loop counter Infinite Loops Fahrenheit and Celsius table by while loop Printing a select menu with while()

Php Code : Using Foreach() To Iterate Through An Array

Using foreach() to Iterate Through an Array in php

 
<?php

    $myarray = array('php', 'is', 'cool');

    foreach($myarray as $key => $val) {
      echo "The value of index $key is: $val<BR>";
    }

    foreach($myarray as $val) {
       echo "Value: $val<BR>";
    }
?>