PHP Expressions and Control

PHP Control Constructs

  1. Looping.
    1. Loop bodies use brackets under same rules.
    2. While loop: repeat some code while a test is true
      1. Test first.
      2. If true run the body then test again.
      3. May run zero times if test is initially false.
      4. Test may become false anywhere within the body, but body will finish anyway.
    3. For loop: An extended while loop.
      1. Initialize a variable
      2. Run while the test is true.
      3. Incrementing each iteration.
    4. Do loop: A while loop, but must always run the first iteration.
    [ PHP Loops Source ]
  2. Foreach
    1. Repeat some code for each member of an array.
    2. Form for values, and another for key and value.
    [ PHP Foreach Statement Source ]
  3. Some examples.
    1. Grid: [ 5x7 Source ] [ 10x8 ]
    2. Dot row
      1. This one creates links that send a parameter back to itself.
      2. This creates an interactive page with a server turn-around.
      3. [ Row of colors Source ]