【发布时间】:2013-02-11 16:54:42
【问题描述】:
我有一个 JSON 编码的数组填充成功如下:
$profanityText = json_encode($pds->fetchAll(PDO::FETCH_ASSOC));
稍后我想遍历这些数据并执行以下操作:
$profanityTextArray = json_decode($profanityText);
foreach ($profanityTextArray as $key => $jsons) {
print_r($jsons);
}
当我使用 print_r($jsons) 时,我得到以下输出:
stdClass Object
(
[apple] => yes
[peach] => yes2
[banana] => no
)
(
[apple] => yes
[peach] => yes2
[banana] => no
)
这也很好。问题是我不知道如何在 foreach 循环期间访问各个元素。例如:我希望能够访问苹果和香蕉个体以做出必要的决定。
如何单独访问元素,而不是每行只打印_r?
【问题讨论】: