Control Structures |
| Use |
Syntax |
Example(s) |
| Decide whether or not to do something | if (test) statement | if ($e = 1) print ("hello"); |
| Do this if the If conditions are not met | else statement | if ($e = 1) print ("hello"); else print ("goodbye"); |
| if the if conditions are met, do something. otherwise, check if the elseif conditions are met. if neither of them are met, do the else condition. | if (condition) {do something}; elseif (condition) {do something else}; else {do something different}; | if ($e = 1) print ("hello"); elseif ($e = 2) print ("goodbye"); else print ("ERROR"); |
| Do a loop x amount of times. | for (x=1;x<5;X++){do something} | for (x=1; x<5; X++;){print "Hello"} |
| loop through an array and print out its items | foreach($randomVar as $otherRandomVar) {do something} | foreach($row as $item){print "<td>"; print "$item"; print "</td>";} |
| runs the cheack after it runs, this means it garinteed to work | do{statement} while(test) | = 0; do{echo ;} while ( > 0); |