【问题标题】:Accessing associative arrays in PHP在 PHP 中访问关联数组
【发布时间】:2011-04-20 00:26:14
【问题描述】:

我想在下面的PHP中访问关联数组中的索引'memo'

$variables["thelistitems"];
print_r($variables["thelistitems"]);

输出

Array
(
    [0] => Array
    (
        [productid] => prod:c6dbdd62-dc13-6421-5a94-c8cd871a59d3 
        [memo] => dummy 
        [taxable] => 0 
        [unitweight] => 0 
        [unitcost] => 450.02 
        [unitprice] => 445.02 
        [quantity] => 1
    )
) 

【问题讨论】:

  • ....这有什么问题?您为实现这一目标做了什么尝试?

标签: php arrays associative


【解决方案1】:

你本质上拥有的是一个关联数组的数组。所以要访问第一个备忘录,它是

 $variables["thelistitems"][0]["memo"]

要访问每个备忘录,您需要执行以下操作

foreach($variables["thelistitems"] as $listitem) {
    $memo = $listitem["memo"];
}

【讨论】:

    【解决方案2】:

    你想要这个吗?

    $variables["thelistitems"][0]['memo']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-05
      • 1970-01-01
      相关资源
      最近更新 更多