multi-dimension arrays in PHP

Robert Edwards Robert.Edwards at
Fri Mar 7 11:00:09 EST 2003

On Thu, 6 Mar 2003 08:08 pm, Paul Bryan wrote:
> I think you might find this is related to the register_globals
> configuration option in your php.ini file. What I think is happening is
> that when you add the key 'myarray' to the $_SESSION array, the variable
> $myarray is being registered globally. In other words, $myarray points to
> the same object as $_SESSION['myarray'].
> register_globals is a convinience that should generally be avoided. See
> for more
> information.
> If I'm right, you can turn register_globals off in your php.ini. Note that
> this could quite easily break any code already written. Make sure you read
> about register_globals first. There's more info at
> If I'm wrong, or turning register_globals off isn't an option (I'm stuck
> with a server like that because of a lot of code that breaks with
> register_globals off), you could always try:
> $sess_array = $myarray; # They should be two seperate variables now
> $_SESSION['sess_array'] = $sess_array.; # Now you can change $myarray
> This might also work (and requires one less variable):
> $_SESSION['sess_array'] = $myarray; # Note the different key name
> Otherwise, there's info about the mailing lists here
> Good luck,
> Paul.

Bingo! - Right on the money! I didn't even consider that the $_SESSION[] 
superglobal array might get messed with the register_globals stuff. I did as 
you suggest and used a different label for the array, and all is now well 
again. So it had nothing to do with multi-dimensional arrays after all!

Thanks for your quick and very perceptive help.


Bob Edwards.

More information about the linux mailing list