PHP basics: echo, variables and constants
Answers are for parents and teachers.
1
Write a PHP block that stores your favourite book title in a variable and prints: My book is …, using double quotes.
<?php $title = "Sea Stories"; echo "My book is $title"; ?>
2
What do these print? (a) $x = 2; $x = $x + 3; echo $x; (b) echo gettype("7");
(a) 5; (b) string, because "7" is in quotation marks.
3
Find the three mistakes: <? php $name = "Omar" echo 'Hello $name'; ?>
A space in the opening tag (write <?php); a missing semicolon after "Omar"; and single quotes, which will not print the value (use double quotes).
4
Why is the pass mark of a school better as a constant than as a variable?
It must stay the same through the whole site, and a constant cannot be changed by mistake.
5
What would the visitor see if a PHP block contained only a comment?
Nothing from that block: PHP skips comments and prints nothing.