php · level 1 · unit 2 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Put something new in a box and the old thing is gone.
A variable holds one value at a time. Put a new value in and you the old one. The old value is gone for good.
You can copy one box into another. $snack = $treat; puts a copy of what is in $treat into $snack. Change $treat later and $snack keeps its copy.
A dot, ., will strings into one longer string: "Hot" . "dog" gives "Hotdog". The dot adds no spaces, so put any spaces you need inside the quotes.
<?php
$mood = "sleepy";
$mood = "happy";
echo "I feel " . $mood . "\n"; Spaces around the . make your code easier to read, but they never appear in the output.
guess first
Copy, then change. What will this show?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<?php
$treat = "crisps";
$snack = $treat;
$treat = "apple";
echo $snack . "\n";
your turn
Your turn. Join a whole name together.
Type a first name and a last name in the blanks. Then run it to join them into one greeting.
fix it
The dog's name is squashed. Can you fix it?
- Run it and read the output closely. What is missing between the comma and Biscuit?
- The dot joins strings exactly as they are. It never adds a space for you.
- Add a space after the comma, inside the quotes on line 3, then press run.
nailed it
you swapped and joined your boxes. :D
- A new value overwrites the old one in a box.
- Copying a box copies the value inside it.
.joins strings but never adds spaces.
new words in your collection
- overwrite
- join
This lesson isn’t saved. A free account remembers every lesson you finish.