Thanks Marek, That's exactly what I was looking for. I also found
another solution, which was to build a second array with the information
I want and merge the two arrays together with +. I like eval better :)
thanks again.
For anyone that is interested this works too.
$a = 'THREE';
$b = 3;
$data1 = array('ONE'=1,'TWO'=2);
$data2[$a] = $b;
$test = $data1 + $data2;
-Original Message-
From: Marek Kilimajer [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 18, 2002 1:54 AM
To: PHP
Subject: Re: [PHP] Please, Help dynamicaly creating an Array
Try eval(), like this:
$str= 'THREE'=3, 'FOUR'=4;
eval(\$data2 = array('ONE'=1,'TWO'=2,$str););
Max Sullivan wrote:
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
)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php