Welcome to Episode 03 of your PHP journey!
In this episode, we’ll learn all about variables, various data types, and how to use constants in PHP.
A variable is a container used to store data like strings, integers, booleans, etc.
- All PHP variables start with a
$sign. - PHP is loosely typed, so you don’t need to declare the type.
$name = "Aman";
$age = 24;PHP provides multiple built-in data types:
| Type | Example | Description |
|---|---|---|
| String | "Hello" |
Sequence of characters |
| Integer | 24 |
Whole number |
| Float | 81.23 |
Decimal number |
| Boolean | true, false |
True/False values |
<?php
$name = "Aman";
$age = 24;
$marks = 81.23;
$isMarried = true;
echo "My name is = " . $name;
echo "<br>My age is = " . $age;
echo "<br>My marks are = $marks%";
echo "<br>Are you married = $isMarried";
echo "<br><br>";
var_dump($name);
echo "<br>";
var_dump($age);
echo "<br>";
var_dump($marks);
echo "<br>";
var_dump($isMarried);
?>My name is = Aman
My age is = 24
My marks are = 81.23%
Are you married = 1
string(4) "Aman"
int(24)
float(81.23)
bool(true)
🔎
trueprints as1when echoed directly.
Constants are like variables, but their values cannot be changed once defined.
define("SITE_NAME", "Learn PHP with Varun");
echo SITE_NAME;🚫 You don’t use
$with constants.
- Use
.for string concatenation in PHP. - Use
var_dump()to check type + value. - Constants are global and accessible anywhere.
htdocs/
└── php-tutorial/
└── Episode_03_Variables/
└── variables.php
→ Episode 04: Constants and Comments in PHP
In the next episode, we’ll explore how to use comments in PHP and go deeper with constants!
Try changing values and types in your code to see how PHP behaves. Practice is the key to confidence! 🔥