php · level 1 · unit 2 · lesson 3
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Give every box a name that tells you what is inside.
After the $, a name starts with a letter or an underscore, _. Then use letters, digits and underscores. No spaces, and no digit straight after the $, so $2nd_place will not work.
Variable names are , so $Pet and $pet are two different boxes. Pick one way to write each name and stick to it.
Good names say what is inside, like $best_friend rather than $x. Small letters with underscores between the words is called , because the name lies long and low, like a snake.
<?php
$best_friend = "Priya";
$favourite_food = "pasta";
echo $best_friend . " loves " . $favourite_food . "\n"; Long, clear names cost nothing, and they save you guessing later what $x meant.
guess first
Two boxes, nearly the same name. What will this show?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<?php
$Pet = "cat";
$pet = "dog";
echo $Pet . "\n";
your turn
Your turn. Name a box for your favourite book.
Think of a clear snake_case name for a box that holds your favourite book. Type it in both name blanks and the book title in the other blank, then run.
fix it
This name has a gap in it. Can you fix it?
- It is a ParseError on line 2. Look closely at the name of the box.
- Names cannot contain spaces. PHP reads
$favourite, then gets lost at colour. - Join the words with an underscore,
$favourite_colour, on both lines, then press run.
nailed it
your boxes have good names now. :D
- Names start with
$, then a letter or underscore. - No spaces in names, and
$Petis not$pet. - snake_case names say clearly what is inside.
new words in your collection
- case-sensitive
- snake_case
This lesson isn’t saved. A free account remembers every lesson you finish.