Introduction:
Variables in PHP are used to store data that can be accessed and modified throughout the script. PHP variables start with a $
symbol and do not require explicit type declaration since PHP is loosely typed.
Example:
<?php
$name = "John Doe"; // String
$age = 25; // Integer
$isStudent = true; // Boolean
echo "Name: $name, Age: $age, Student: $isStudent";
?>
Explanation:
$name
is assigned a string value"John Doe"
.$age
is assigned an integer value25
.$isStudent
is assigned a boolean valuetrue
.- The
echo
statement outputs the concatenated string along with variable values. PHP automatically converts the variables to strings where required.