-1
I'm迭代迭代:PHP跳过阵列stdClass的
foreach ($arr as $A) {
$THIS=$A->w->b;
}
这里是我迭代通过阵列的一个示例:
Array
(
[0] => Array
(
[w] => stdClass Object
(
[b] => THIS
)
[1] => Array
(
[w] => stdClass Object
(
[b] => THIS
)
[2] => Array
(
[w] => stdClass Object
(
[b] => THIS
)
[3] => Array
(
[z] => stdClass Object
(
[whatever] => NOT THIS
)
)
我需要从[x]
检索THIS
值stdClass每个数组的对象; [0]
,[1]
,[2]
等。但我不需要从[z]
中检索具有不同关键字的值。
因此运行上面的代码时,我成功地检索所需THIS
值,但在整个不包含stdClass的对象我想要的数组进行遍历时,我得到反复的错误:
PHP Notice: Undefined property: stdClass::
会是什么是否可以通过哪种最简单的方式设置迭代跳过某些不需要的对象?或者如果所需的对象不存在,则将其设置为跳过?
什么是'this'和'不this'? – aldrin27
因为这是一个更大阵列的例子,它就是我想要的。 –
你的代码和你的例子根本不匹配。你为什么不写一个实际上(试图)处理你的样本数据的代码,以便我们看到它的错误? –