Skip to content
Guest
Learn PHP · Course Syllabus Show lessons
PHP 8 Basics · 7 min read · Beginner

Variables, Types & String Interpolation

Run your first PHP 8 script in the browser, declare $variables cleanly, and interpolate values inside double-quoted strings.

What you'll learn

  • Start PHP scripts cleanly with <?php and declare(strict_types=1);
  • Understand $variables, string concatenation (.), and double-quote interpolation
  • Use the null coalescing operator (??) for safe defaults

PHP 8 powers a massive portion of the modern web (from Laravel and Symfony to WordPress). Every variable starts with $, and statements end with ;.

String Interpolation vs. Single Quotes

  • Double quotes ("...") evaluate variables like "Hello, $name!".
  • Single quotes ('...') print text literally without parsing variables.

Fill-in-the-Blank Exercise

PHP Variable & Null Coalescing

Declare a $track variable and fall back to 'Guest' when $user is null.

<?php
track = "PHP 8";
$label = $user  "Guest";
echo "Welcome, $label!";

Try It Yourself (PHP 8 in Your Browser)

PHPYour First PHP 8 Script
PHP 8 Output (WebAssembly)

Click Run PHP to execute real PHP 8 right in your browser.

Check Your Understanding

Score: 0 / 1

1. Which quote style evaluates $name inside a PHP string?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind