AW: [PHP] Variable Names

2007-11-29 Thread Frank Ruske
 "bar");

var_dump($my_array);
?>
array(1) { [0]=>  string(3) "bar" }


Regards Frank

-Ursprüngliche Nachricht-
Von: Shaun [mailto:[EMAIL PROTECTED]
Gesendet: Donnerstag, 29. November 2007 13:57
An: php-general@lists.php.net
Betreff: [PHP] Variable Names


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."";
}
   }

   else {
$_SESSION['ses-app-form']->$key = $value;
//echo "value: ".$key." = ".$value."";
   }
  }
 }


Any Ideas?

Cheers,

Shaun

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



AW: [PHP] Variable Names

2007-11-29 Thread Frank Ruske
 "bar");

var_dump($my_array);
?>
array(1) { [0]=>  string(3) "bar" }


Regards Frank

-Ursprüngliche Nachricht-
Von: Shaun [mailto:[EMAIL PROTECTED]
Gesendet: Donnerstag, 29. November 2007 13:57
An: php-general@lists.php.net
Betreff: [PHP] Variable Names


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."";
}
   }

   else {
$_SESSION['ses-app-form']->$key = $value;
//echo "value: ".$key." = ".$value."";
   }
  }
 }


Any Ideas?

Cheers,

Shaun

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php