Generally Variables in PHP are defined by ” $” symbol followed by name
of the Variable. Variables in PHP are case sensitive.
[php]
<!DOCTYPE html>
<html>
<body>
<?php
function myVariables()
{
$age = 25; // local scope
echo "The Variable age defined inside the function and the value is: ".$age." <br><br>";
}
myVariables(); // if you call the age variable outside function, will give an error
echo "The Variable age outside function is: ".$age."";
?>
</body>
</html>
[/php]
Output:
Output:
[php]
The Variable age defined inside the function and the value is: 25
[/php]
But, global variables can also be accessed inside the function also, by using the keyword global
before the variable declaration.
static
. Static is kept before the variable, at the first time of declaration.