views:

49

answers:

2

I'm trying to access an associative array's key and value from within the same array. If I have 3 pairs in my array. Can I use the value of let's say the values of something and other within the third one another?

$gar = array("something" => "something value", 
             "other" => "other value", 
             "another" => something . other 
       );

The idea is that another's value will be "something valueother value".

Is this possible? Is there a way to accomplish the same thing?

+5  A: 

how about just something like this

$gar = array("something" => "something value", 
         "other" => "other value"
   );

$gar["another"] = $gar["something"] . $gar["other"];
Marek Karbarz
+3  A: 

It should be fine if you use it on multiple lines like this:

$gar = array();
$gar["something"] = "something value";
$gar["other"] = "other value";
$gar["another"] = $gar["something"].$gar["other"];

You could even put the above sequence in a loop then.

Crimson
I went for this, just because it's a little cleaner looking, although both work perfectly.
drummer