【发布时间】:2026-01-15 03:15:01
【问题描述】:
我有一个数组,它是使用 Amazon SimpleDb 进行选择查询的结果。
这是我 print_r($result); 时的示例数据;
Array ( [0] => Array ( [Name] => 5140ede647e74
[Attributes] => Array (
[0] => Array ( [Name] => test_id [Value] => 5140ede647e74 )
[1] => Array ( [Name] => test_name [Value] => test1 )
[2] => Array ( [Name] => last_update [Value] => 1363209702 )
[3] => Array ( [Name] => created [Value] => 1363209702 ) ) ) )
如果我想提取 test_id 和 test_name,我该怎么做?我目前正在做以下事情
<?php foreach ($result as $item) {
echo $item['Attributes'][0]['Value'];
echo $item['Attributes'][1]['Value'];
} ?>
但我想通过引用“test_id”和“test_name”来做到这一点,因为当我删除数据所在的域并重新输入数据时,每个属性的顺序都会改变,所以我不能相信 $ item['Attributes'][0]['Value'] 将永远是 test_id
谢谢!
【问题讨论】:
-
请重新发布
print_r()的输出,但请保留格式,以便在多行之间正确缩进。 -
@Barmar - 感谢您格式化数组。我学到了下次的技巧。如果您 print_r() 一个数组,当您在浏览器中查看它时,它的格式不正确。但至少在 Firefox 中,当我查看源代码时,数组的格式很好。
-
在页面中打印时将其包裹在
<pre>...</pre>中。
标签: php multidimensional-array amazon-simpledb