PHP variables can take any type of data and change their type within the page also. ( in above example $my_var changes with type of data ) . It depends on its most recent assignment.
Scope of Variable
Local & Global
The variables declared as global are available throughout the script ( including inside the functions ).
Variables declared inside functions is know as local variable ( to that function ) and are only available inside the function. So local variables declared inside a page are not available inside the functions of the page.
echo $v3; // Output is 7
The associative array $GLOBALS holds the name of the variables as key and content as value of the variable. Once the variable is declared as element of $GLOBAL variable, then it is available throughout the script (including inside the functions).
Output is here. See how static variable value is retained after execution of first call of the function whereas the local variable is destroyed.
Static varaible :1, Local Variable :1
Static varaible :2, Local Variable :1
Life of a variable
All variables are used within the page or within the script present in a page. As you are reading this page some variables are used to display the content of the page. These variables are lost as soon as this page execution is completed at server and downloaded to your browser. So how to pass the data or retain the data across the pages ?