A variable in PHP is a labelled box that stores one piece of information, so your page can use it again and again. This post is the official notes page for Video 3 of the PHP & MySQL Website Development Course by Coding Cush. Missed the setup lesson? Read the Video 2 notes on installing XAMPP and VS Code first. Today we open up that page's code and understand every part of it.
First, the Syntax Rules Every PHP File Follows
PHP code lives between an opening tag and a closing tag; everything outside them is plain HTML. Three rules matter from day one. First, almost every PHP statement ends with a semicolon — the full stop of PHP. Forget it and PHP stops with a parse error. Second, variable names are case-sensitive: $courseName and $coursename are two different boxes. Third, keywords like echo work in any case, but professionals write them in lowercase so code stays consistent. Learn these three and half of all beginner errors disappear.
Comments: Notes for Humans That PHP Ignores
A comment is written for people, not the server. Start one with two forward slashes and the rest of that line is ignored when the page runs. In today's file, the first line inside the PHP tags is a comment naming the lesson, so anyone opening variables.php months later knows what it is for. Good comments explain the reason behind the code.
Variables: A Labelled Box for Your Data
Think of a variable as a box with a label on it. The label is the name, which always begins with a dollar sign in PHP, and inside the box sits one value. You create and fill it in one line: name on the left, equals sign in the middle, value on the right. That equals sign does not mean "is equal to" like in maths; it means "store this value in that box." Naming rules are simple: start with a letter or an underscore, never a number, never spaces — and names are case-sensitive. The PHP Manual's variable basics page lists the full rules.

The Five Data Types in This Lesson
Every value in PHP has a type, and the type decides what you can do with it. This lesson uses the five types you will meet in almost every beginner program.
| Data type | What it stores | Example in variables.php |
|---|---|---|
| String | Text, always inside quotes | "PHP & MySQL Website Course" |
| Integer | Whole numbers, no quotes, no decimals | 30 lessons |
| Float | Numbers with a decimal point | 4.9 rating |
| Boolean | Only true or false | Is the course free? true |
| Null | Nothing yet — an empty box on purpose | Certificate not decided yet |
Notice the pattern: text gets quotes, numbers do not. Put quotes around 30 and PHP treats it as text, not the number thirty — remember this for the Viva Corner. And null does not mean zero or empty text; it means no value has been stored yet — perfect for a certificate that only exists after a student finishes.
The Full Code: variables.php
Here is the complete file from Video 3, saved inside your skillnest folder. Type it yourself instead of copying — typing builds habits reading cannot.
<?php
// Course details for SkillNest Academy
$courseName = "PHP & MySQL Website Course";
$totalLessons = 30;
$rating = 4.9;
$isFree = true;
$certificate = null;
echo "<h1>" . $courseName . "</h1>";
echo "Total lessons: " . $totalLessons;
echo "Rating: " . $rating . " out of 5";
echo "Free course? " . $isFree;
var_dump($courseName);
var_dump($totalLessons);
var_dump($rating);
var_dump($isFree);
var_dump($certificate);
?>Read it top to bottom: the comment names the file, five variables store the course details, four echo lines send them to the page — joining text and variables with the dot operator, which glues pieces together — and five var_dump lines inspect every box. For the bigger picture, revisit the Video 1 course roadmap and project tour.
Echo: Sending Your Data to the Page
Echo is how PHP speaks to the browser. Whatever you echo becomes part of the HTML the server sends back, exactly where the PHP block sits — the browser receives a real heading, never the PHP code itself. Now for the famous surprise. When you echo the boolean true, the page shows the number 1. When you echo false, the page shows nothing at all — and null also prints as nothing. This is not a bug: PHP converts true to 1 for display, and false and null to empty text. Remember it, and you will never hunt for this invisible problem later.
Echo vs Print, and Double Quotes vs Single Quotes
PHP gives you a second way to send output: print. For everyday work they behave the same. Echo can print several pieces at once and returns nothing; print prints one piece and returns the number 1. Quotes matter more. Text in double quotes is smart: PHP looks inside and replaces variable names with their values. Text in single quotes is literal: PHP prints exactly what you typed, dollar sign and all. Use double quotes when a variable belongs inside the sentence; single quotes when you want the text untouched.
var_dump: The X-Ray for Your Variables
Echo shows you the value but hides the type — and the type is often where the real problem lives. var_dump is the X-ray tool that shows everything at once: the type, the length for text, and the exact value. Run it on our five variables and you get string(26) for the course name — text of 26 characters — int(30) for the lessons, float(4.9) for the rating, bool(true) for the free answer, and NULL for the certificate. The PHP Manual's var_dump reference page documents it in full. Use it while debugging, then remove those lines before a page goes live.
Bug of the Day: The Missing Semicolon
Today's bug is the most common error in all of PHP: a missing semicolon. Delete one semicolon and PHP answers with a parse error and refuses to run anything. Here is the lesson hidden inside the message: PHP often reports the problem on the line after the mistake. In the video, the error pointed at line 9 while the missing semicolon was really on line 7, because PHP only realised something was wrong when it reached the next instruction. So when a parse error names a line, check that line — then the line just above it.
Your Turn #3
Create four variables for your own dream website: its name, its page count, its target rating, and whether it will be free. Then echo one full sentence that uses all four, run it, and comment DONE on Video 3 with your website's name. In Video 4 we start making PHP calculate with your numbers.
Viva Corner: What Is the Difference Between "5" and 5?
Today's viva question: what is the difference between "5" in quotes and 5 without quotes? Quoted, it is a string — text that looks like a number. Unquoted, it is an integer — a real number PHP can calculate with. They can look identical when echoed, which is exactly why var_dump exists: it reveals the truth that echo hides. Interviewers love this question, because in PHP, how a value is written decides what it is.
Frequently Asked Questions
Do I need to declare a variable before using it in PHP?
No. PHP creates the variable the first time you store a value in it, and decides the type from that value.
Why does echo true print 1, but echo false prints nothing?
Because PHP converts values for display: true becomes the text "1", while false and null become empty text. The stored values are still proper booleans.
What is the difference between echo and print in PHP?
Both send output to the page. Echo can print several pieces at once; print prints one piece and returns 1. Echo is the standard choice.
How do I check the type of a variable in PHP?
Use var_dump on the variable. It prints the type, length (for text) and exact value — the quickest debugging tool a beginner has.
Can a variable name start with a number in PHP?
No. It must start with a letter or underscore, after the dollar sign. Numbers may follow, and names are case-sensitive.
Watch Video #3 and What Comes Next
You now understand the building blocks of every PHP page: statements that end properly, comments that explain, variables that store, types that decide behaviour, and echo that publishes. In Video 4 we put those numbers to work with operators — totals, discounts and comparisons. Watch the full lesson, do Your Turn #3, and I will see you there.
Watch Video #3 on YouTube: Variables, Data Types and Echo in PHP
Leave a Comment