PHP Variables

PHP variables are used to store data like numbers, strings, or arrays. A variable starts with the $ symbol.

// Declaring variables
<?php
$name = "Ali"; // String
$age = 25; // Integer
$height = 5.9; // Float
$isStudent = true; // Boolean
?>

1. String

Text inside quotes like "Hello" or 'World'.

$text = "Academy of Information Technology";

2. Integer

Whole numbers without decimal.

$age = 20;

3. Float (Double)

Numbers with decimal point.

$price = 99.99;

4. Boolean

Only two possible values: true or false.

$isLogin = true;

5. Array

Collection of multiple values in a single variable.

$students = ["Ali", "Sara", "Ahmed"];

6. NULL

Variable with no value.

$result = NULL;
  • Variable names are case-sensitive: $Name and $name are different.
  • Start with $ and a letter or underscore, not a number.
  • No need to define data types separately — PHP is loosely typed.