Php Global Variables Codeigniter Php Global Variables
Php global variables variables are automagically available in all contexts in function and global scopes. They are named respectively: $ POST, $ GET, $ COOKIE, $ ENV and $ SERVER. Additionally, a new array called $ REQUEST was added, which contains all $ GET, $ POST and $ COOKIE variables. Variables defined outside of a function are called global variables. They exist in one scope. Variables defined inside of a function are called local variables. The tips to access a global variable inside a function is to use the global keyword. This tells the PHP interpreter that further use of the named variable inside a function should refer to the global variable with the given name, not a local variable. Print the entire $GLOBALS array using PHP's functions for processing associative arrays: <?php reset($GLOBALS); while (list($key, $var) = each($GLOBALS)) { print "$key => $var\ n<br>\ n"; } ?> PHP's list() and each() functions to iteratively process the $GLOBALS array. It then prints the keys names of the variables stored in the $GLOBALS array and their corresponding values. To access a variable that is not declared within the current function, you must do one of two things: either access it through the $GLOBALS array or declare the variable as the global variable. |
0 Response to "Php Global Variables"
Posting Komentar