2009-10-31 103 views
1

我想从同一个数组中访问关联数组的键和值。如果我的阵列中有3对。我可以使用somethingother的值在第三个another之内吗?使用来自同一个数组内的关联数组值

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

这个想法是,他人的价值将是“值得其他价值的东西”。

这可能吗?有没有办法完成同样的事情?

回答

4

,如果你使用它在多行这样它应该是罚款:

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

你甚至可以把上面的序列中的循环即可。

+0

我这样做,只是因为它看起来有点干净,尽管两者都很完美。 – drummer 2009-10-31 10:30:52

6

如何只像这样

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

$gar["another"] = $gar["something"] . $gar["other"];