获得精确键的对象数组对象
问题描述:
Array
(
[1] => stdClass Object
(
[position] => 1
[priority] => 1
[percentage] => 100
)
[131] => stdClass Object
(
[position] => 11
[priority] => 12
[percentage] => 80
)
)
这是我的对象数组。获得精确键的对象数组对象
为什么我不能像这样得到对象:$ a = $ niz [1]?
答
将stdClass对象转换为php数组,以便以正常方式访问它。
$niz = get_object_vars($niz);
$a = $niz[1];
print_r($a);
+0
它已经是PHP的数组对象 – consigliere
这对我来说很好。你可以做'var_dump($ a)'(或'var_dump($ niz [1])')并发布结果吗? – Halcyon
你可以 - 你得到什么错误 – Steve
消息:未定义的偏移:1这是错误。这非常奇怪 – consigliere