【问题标题】:Using associative array values from within the same array使用同一数组中的关联数组值
【发布时间】:2009-10-31 07:30:43
【问题描述】:

我正在尝试从同一个数组中访问关联数组的键和值。如果我的数组中有 3 对。我可以在第三个another 中使用假设somethingother 的值吗?

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

这个想法是另一个人的价值将是“一些有价值的东西”。

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

【问题讨论】:

    标签: php arrays associative-array


    【解决方案1】:

    这样的事情怎么样

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

    【讨论】:

      【解决方案2】:

      如果你像这样在多行上使用它应该没问题:

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

      你甚至可以把上面的序列放在一个循环中。

      【讨论】:

      • 我选择了这个,只是因为它看起来更干净一些,尽管两者都很好用。
      【解决方案3】:

      我的问题也谈到了类似的问题。希望有帮助! :)
      PHP - Accessing array element within the same array

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-02-05
        • 2022-01-12
        • 2011-02-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多