php variables

PHP variable is just a assigment to refer a location in memory where some value is stored. You can not refer to memory addresses directly. Since PHP variable friendly refered to memory locations. All variables in PHP are prefixed with a dollar sign . PHP parser to recognize the variable dollar sign and dollar sign is not technically part of the variable name.

PHP variables most of part have a single scope. which single scope most used included and required files as well.

<?php
$b = 1;
require 'b.inc';
?>

Here the $b variable will be available within the included b.inc script.Any variable used inside a function is called local function scope.

PHP - variable Example:


<?php
$b = 1; /* global scope */
function test()
{
echo $b; /* reference to local scope variable */
}
test();
?>

This example will not produce any output because echo statement refers to a local version of the $b variable and it has not been assigned a value within this scope.





Content