1

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?

2 Answers 2

6

how about just something like this

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

$gar["another"] = $gar["something"] . $gar["other"];
Sign up to request clarification or add additional context in comments.

Comments

4

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.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.