Please, Help dynamicaly creating an Array
| From: | Max Sullivan | Date: | Tue, 17 Sep 2002 23:22:20 +0000 |
| Subject: | Please, Help dynamicaly creating an Array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-116667@lists.php.net to get a copy of this message | ||
I am trying to populate array values and keys from a variable with no
luck.
Lets say I have the following array.
$data1 =
array('ONE'=>1,'TWO'=>2,'THREE'=>3,'FOUR'=>4);
And I want to create part of the array with the string below:
$str= "'THREE'=>3, 'FOUR'=>4";
$data2 = array('ONE'=>1,'TWO'=>2,$str);
How can I create $data2 to work the same as $data1. When I try the
above for $data2 a new key is created ([0]) for $str. And I end up with
...'TWO'=>2, [0] => 'THREE'=>3, 'FOUR'=>4. It
doesn't "interpret" the
variable how I expect it to, instead it see's $str as a value. I guess
the question is how can I make php use the string literally.
I've tried everything I can think of and I think my head is about to
explode :). Is it possible to create an Array this way? Any help is
appreciated!!
print_r($data1):
Array
(
[ONE] => 1
[TWO] => 2
[THREE] => 3
[FOUR] => 4
)
print_r($data2):
Array
(
[ONE] => 1
[TWO] => 2
[0] => 'THREE'=>3, 'FOUR'=>4
)