访问在PHP关联数组 [英] Accessing associative arrays in PHP
本文介绍了访问在PHP关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要访问索引备忘录在PHP关联数组在下面
$变量[thelistitems];
的print_r($变量[thelistitems]);
输出
阵列
(
[0] =>排列
(
[产品id] => PROD:c6dbdd62-dc13-6421-5a94-c8cd871a59d3
[备忘录] =>假
[征税] => 0
[unitweight] => 0
[unitcost] => 450.02
[单价] => 445.02
[数量] => 1
)
)
解决方案
什么你必须要有具有关联数组的数组。所以访问第一备忘录,这是
$变量[thelistitems] [0] [备忘录]
要访问每个备忘录,你会做这样的事情。
的foreach($变量[thelistitems]为$列表项){
$备忘录= $列表项[备忘录];
}
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
)
)
解决方案
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"];
}
这篇关于访问在PHP关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文