PHP - 引用数组中的 stdclass 对象
PHP - refer to stdclass object within array
上下文
我正在尝试参考下面的 值:
Array (
[0] => stdClass Object (
[label] => John Smith
[attributes] => Array (
[class] => sf-level-0 sf-item-14
)
[value] => smith-john
[depth] => 0
[count] => 3
)
[1] =>... etc.
问题
假设数组名为 $array,正确的格式是什么?我已经试过了 array[0]->['value']
,但是没有用。
很难说你的格式。但是:
$array[0]->value
数组中的第一个元素是 stdClass Object
类型,因此要访问其成员,您可以使用对象访问器 ->
而不是数组语法。
PS:感谢 Marc 通过他的编辑让事情变得清晰。
上下文
我正在尝试参考下面的 值:
Array (
[0] => stdClass Object (
[label] => John Smith
[attributes] => Array (
[class] => sf-level-0 sf-item-14
)
[value] => smith-john
[depth] => 0
[count] => 3
)
[1] =>... etc.
问题
假设数组名为 $array,正确的格式是什么?我已经试过了 array[0]->['value']
,但是没有用。
很难说你的格式。但是:
$array[0]->value
数组中的第一个元素是 stdClass Object
类型,因此要访问其成员,您可以使用对象访问器 ->
而不是数组语法。
PS:感谢 Marc 通过他的编辑让事情变得清晰。