Control Structures¶
Control structures are PHP statements that control the flow of execution.
if / elseif / else if
while
do-while
for
foreach
break
continue
switch
match
declare
return
require()
include()
require_once()
include_once()
goto
Usually, instructions and commands are executed one after each other. With control structures, this flow is changed and the execution will go to another part of the code for its next step. For example, inside a loop, when PHP encounters a break command, it will then execute the next command after the loop, instead of the next command sequentially.
<?php
if (rand(0, 1) > 0) {
print 'Hello, world.';
} else {
print 'World : hello!';
}
?>