Variables spanning multiple sections of code on single page

A

Anonymous

Guest
I am very new to PHP and am having difficultly understanding the scopes for variables.

Is is possible to create a variable at the top of a page in one section of code, than use this variable later in the page in various other sections of code.

For example:
Code:
<?php
$var = 0;
//php code
?>
//HTML CODE

<?php
 echo $var;
?>

Thanks!
 
once a variable is defined, it is always defined until the script is finished.
With that being said..

Variables cannot be passed from the inside of a function or class.
A variable can be passed to a function.
 
Back
Top