Tuesday, November 22, 2011

Global Variable/Array in PHP

The global variable is declared in the function instead of in the main as in C language.


<?PHP

$my_global_array = array(); // Global array set up in main
$my_global_variable; // Global variable set up in main
.
.
.


funtion a() {
global $my_global_array, $my_global_variable;
// declare the array and variable in main as global variable
.
.
.

}

function b() {
global $my_global_array;
// only takes this global array as the global variable is not needed in this function
.
.
.

}


?>





No comments:

Post a Comment