CodeBlanks Logo Icon CodeBlanks

Summary - Variables

PHP course · Beginner · Lesson 12/116

Combine variable declaration, assignment and checks to build a user info card.

Summary: Variables

In this group you built the foundation of variables. You learned:

  • declaring variables with $ and =.
  • naming principles and case sensitivity.
  • reassignment, increasing and decreasing with ++ and --.
  • combining with . and doing arithmetic with numbers.
  • checking variables with isset() and unset().

Now you will combine all of this into a user info card.

Exercise Build a user info card

Assign "Alex" to $userName and "Berlin" to $city. On the first line, print Alex - Berlin using $userName . " - " . $city . "\n". Remove $city with unset($city). On the second line, print "City set: " . isset($city) . "\n".

Show example solution
On the first line combine $userName and $city with a dot; then unset, then isset on the second line.
Example solution:
<?php
$userName = "Alex";
$city = "Berlin";
echo $userName . " - " . $city . "\n";
unset($city);
echo "City set: " . isset($city) . "\n";

Test yourself

  1. Which function is used to delete a variable?

    • unset()
    • isset()
    • delete()
    • remove()
    Show answer

    unset() — Correct! unset() completely destroys a variable.

  2. Declare the counter

    ____visitors = 0;
    Show answer
    $visitors = 0;
  3. Match each concept to its description

    $ sign
    starts a variable name
    ++
    increases by one
    .
    combines two values
    unset()
    deletes the variable

All lessons in Beginner