在 PHP 中访问关联数组

发布于 2024-09-26 02:31:39 字数 474 浏览 1 评论 0原文

我想访问 PHP 中

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

Output下面的关联数组中的索引“memo”

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

I want to access the index 'memo' in the associative array in PHP below

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

Output

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

许仙没带伞 2024-10-03 02:31:39

您本质上拥有的是关联数组的数组。因此,要访问第一个备忘录,要

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

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

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

What you essentially have is an array of associative arrays. So to access the first memo, it's

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

To access each memo, you'd do something like this

foreach($variables["thelistitems"] as $listitem) {
    $memo = $listitem["memo"];
}
紫﹏色ふ单纯 2024-10-03 02:31:39

你想要这个吗?

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

Do you want this ?

$variables["thelistitems"][0]['memo']
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文