PHP Variables
![]() |
PHP Programming |
PHP variables must have $ code before the variable. Example:
A variables above is myString for Hello World! as String, myInt for 5 as integer and myFloat for 0.5 as float.
Note :
A variable must same with variable's string that's created, because if not same with variable string that's created first although that's type is same but has different of the format of variable like uppercase, etc., the variable can't be used. Example :
This example can't run because the variable of color has a three different variables.
PHP Global and Scope
The variable in outside the function has a global scope and can be accessed outside the function. Example :The variable in inside the function has a local scope and can only accessed within the function. Example :
PHP The Global Keyword
The global keyword is used to access the variable within the function. Example:PHP also stores all global variable in array with $GLOBALS['index']. the $GLOBALS['index'] is saves a variable for access the function. Example :