×

php · level 1 · unit 3 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Quotes turn a number into text.

Every value has a . Text in quotes is a string. A whole number with no quotes, like 12, is an . Put quotes round it, "12", and it becomes a string that happens to hold digits.

The dot always joins, so "5" . "3" gives 53. The plus sign always does maths, so 5 + 3 gives 8. PHP even does maths with "5" + "3", as long as the text looks like a number.

gettype is a : a ready-made command that comes with PHP. Put a value in its brackets and it hands back the name of its type.

<?php
$eggs = 12;
$label = "12";
echo gettype($eggs) . "\n";
echo gettype($label) . "\n";

Text that does not look like a number, like "cat" + 1, stops PHP with a TypeError.