A PHP variable is the name of the memory location that holds data. It is temporary storage.
Syntax:
$variableName=value;
In PHP, variables are declared using the following syntax:
php
$variableName = value;
Here’s a breakdown of this syntax:
$
sign: It is used to declare variables in PHP. It precedes the name of the variable.variableName
: This is the name you choose for your variable. It must start with a dollar sign followed by letters, underscores, or digits (but cannot start with a digit).=
sign: It is the assignment operator, used to assign a value to the variable.value
: This is the actual data assigned to the variable. It can be a string, number, boolean, array, object, or any other data type supported by PHP.
For example:
php
$name = "John";
$age = 25;
$isStudent = true;
This code declares three variables: $name
, $age
, and $isStudent
, and assigns them values of "John"
, 25
, and true
respectively.