Variable Names

From: Date: Thu, 29 Nov 2007 12:56:36 +0000
Subject: Variable Names
Groups: php.general 
Request: Send a blank email to php-general+get-265214@lists.php.net to get a copy of this message
Hi, I seem to be having a problem in assigning a value to an array where the array is called dynamically. e.g. the physical name for the array is "my_array", so: my_array[1] = "test"; works fine. $array_name = "my_array"; $array_name[1] = "test"; does not work. I have tried $$array_name[1] = "test"; but to no avail. Here is my code /** * Adds any posted values from the application form to the session */ function add_form_to_session() { foreach ($_POST AS $key => $value) { if (is_array($value)) { foreach ($value AS $subkey => $subvalue) { $_SESSION['ses-app-form']->$key[$subkey] = $subvalue; //echo "value: ".$key."<br>"; } } else { $_SESSION['ses-app-form']->$key = $value; //echo "value: ".$key." = ".$value."<br>"; } } } Any Ideas? Cheers, Shaun

« previous php.general (#265214) next »