0PricingLogin
PHP Academy · Lesson

Declaring Variables in PHP

Learn how PHP variables work with the $ prefix and dynamic typing.

What Is a Variable?

A variable is a named container that holds a value your program can read and change.

  • In PHP every variable name starts with a dollar sign: $name
  • Variable names are case-sensitive: $age and $Age are different
  • Names must start with a letter or underscore, not a digit

PHP is a dynamically typed language — you never declare the type; PHP figures it out from the value you assign.

Assigning Values

Use the = operator to assign a value to a variable:

<?php
$name = 'Alice';
$age  = 30;
$pi   = 3.14159;
$active = true;

echo $name;   // Alice
echo $age;    // 30

All lessons in this course

  1. Declaring Variables in PHP
  2. PHP Data Types Overview
  3. Echo and Print Output
  4. Type Juggling and Type Casting
← Back to PHP Academy