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

Reply via email to