Using associative array values from within the same array
-
11-09-2019 - |
Question
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?
Solution
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.
OTHER TIPS
how about just something like this
$gar = array("something" => "something value",
"other" => "other value"
);
$gar["another"] = $gar["something"] . $gar["other"];
my question speaks about the analogous problem too. Hope that helps! :)
PHP - Accessing array element within the same array
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow