What is a variable in PHP?
In PHP, a variable is a container for storing data values. It is identified by a dollar sign ($
) followed by the variable name. The variable name in PHP is case-sensitive and should start with a letter or an underscore, followed by any number of letters, numbers, or underscores.
Here's a basic example:
<?php
$variableName = "Hello, World!";
echo $variableName; // Output: Hello, World!
?>
In this example:
$variableName
is the variable.
"Hello, World!"
is the value assigned to the variable.
echo
is used to output the value of the variable.
Variables in PHP can store different types of data, such as strings, integers, floats, arrays, and objects. The type of data a variable holds can change dynamically during the script's execution.