Saturday, December 04, 2004

Make Your Own Global Array in PHP

That's what I want to do. That is, something like this:

make_global($_MYARRAY); (or global $_MYARRAY;)

Then anywhere in code (inside or outside function scope):

$_MYARRAY['this_var'] = "Whatever value I want to give it";

Doesn't appear to be possible. Rather, I can do this:

$sample = array("var1"=>"value1","var2!=>"value2");
/* created within the script or created in a function using the global keyword/scope */


Then, inside a function:

<?php
function this_function()
{
$array_value = $GLOBALS['sample'][0];
}
?>


Explained here.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home