PHP variables are characters that stores value or information such as text or integers in your code. It is important to know that variables in PHP are usually represented by a dollar sign($) followed by the name of the variable. Those variables can be used to hold values or expressions and can have letter names or long phrases that can also represent your variable. The benefits of using variables are that you can use letters and number to create names and labels. There are five basic rules for PHP variables:
Variables in PHP are created the moment you assign a value to it. Variables are the main way to store information in the middle of the PHP variable. Here is some important information about variables:
In addition to that, there are seven ways to construct PHP variables:
Example:$a = -154 or $a = 1234Booleans- tell us whether two values are true or false Example:
$y = false;
$x = 0;
if (is_bool($y) == true) {
echo "looks like a boolean";
}
Example:$var=NULL;
Example: echo 'bobby said: "I will be there" ';
$array = array( low => "high", high => "low" );
class high
{
function go_high()
{
echo "going high.";
}
}
Example:$ab = curl_init()
Variable scopes are scripts that variables uses in PHP function. There are four different types of variable Scopes:
function myPlan ()
{
echo $x; // local scope
}
Global Example:
function myPlan ()
{
$GLOBALS['a']=$GLOBALS['b']+$GLOBALS['a'];
}
Static Example:
function myPlan ()
{
STATIC $y=2;
echo $y;
}
function Parameter Example:
function myPlan($y)
{
echo $y;
}