Skip to content

PHP Variables

Syntax

In PHP, variables are declared using the $ symbol followed by the variable name and can store different types of data.

// Declaring variables
$name = "John"; // String
$age = 30; // Integer
$isAdmin = true; // Boolean
$height = 5.9; // Float
// Accessing variables
echo $name;

Example

<?php
// Assigning values to variables
$name = "Alice";
$age = 25;
// Using variables
echo "Name: " . $name . "\n"; // Outputs: Name: Alice
echo "Age: " . $age . "\n"; // Outputs: Age: 25
?>