PHP Conditionals & Loops Flashcards

1
Q

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!’

A

<?php <br></br> $name = ‘Mike’;
if ( $name == ‘Mike’ ) {
echo ‘Hi, I am ‘ . $name . ‘!’;
}
?>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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.

A

<?php <br></br> $names = array(‘Mike’, ‘Chris’, ‘Jane’, ‘Bob’);
foreach ($names as $name) {
echo $name;
}
?>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly