PHP Conditionals & Loops Flashcards
Create A Variable Called $name and set it to the string ‘Mike’.
Under the variable $name create a if statement that test to see that the $name variable is set to the string ‘Mike’.
Finally, echo the following string inside of the if statement: ‘Hi, I am Mike!’
<?php <br></br> $name = ‘Mike’;
if ( $name == ‘Mike’ ) {
echo ‘Hi, I am ‘ . $name . ‘!’;
}
?>
Using a foreach, create a loop that goes through each of the names in the $names array.
<?php <br></br> $names = array(‘Mike’, ‘Chris’, ‘Jane’, ‘Bob’);
?>
Inside of your foreach loop echo each of the names to the screen.
<?php <br></br> $names = array(‘Mike’, ‘Chris’, ‘Jane’, ‘Bob’);
foreach ($names as $name) {
echo $name;
}
?>