从 arrayObject 中检索键值
这是我的数组:
ArrayObject::__set_state(
array( 'data' =>
array (
'key1' => '573779',
'key2' => 'REF12345',
'key3' => '2010-07-12',
'key4' => '0000-00-00',
'key5' => '2010-07-12',
'key6' => '21654',
'key7' => '0',
'key8' => ArrayObject::__set_state(array( )),
'key9' => ArrayObject::__set_state(array( )),
'key10' => array ( ),
'key11' => array ( ),
)
)
我有兴趣了解如何使用 SPL 检索键的任何值。任何键都可以在数组中包含数组,因此我不确定如何获取值。我想我也许可以使用 ->offsetGet('')
但这只能从最顶层的数组中检索。
This is my array:
ArrayObject::__set_state(
array( 'data' =>
array (
'key1' => '573779',
'key2' => 'REF12345',
'key3' => '2010-07-12',
'key4' => '0000-00-00',
'key5' => '2010-07-12',
'key6' => '21654',
'key7' => '0',
'key8' => ArrayObject::__set_state(array( )),
'key9' => ArrayObject::__set_state(array( )),
'key10' => array ( ),
'key11' => array ( ),
)
)
I'm interested in finding out out how to retrieve any of the values for a key using SPL. Any of the keys can have arrays within arrays so I'm unsure how to obtain a value. I thought I may be able to use ->offsetGet('')
but this only retrieves from the top-most array.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ArrayObject 实现 ArrayAccess 因此您可以简单地使用常规数组表示法访问它们,例如
此外,ArrayObjects 是 IteratorAggregates,因此您可以使用
foreach
迭代它们,并使用任何 SPL 迭代器,包括 递归迭代器迭代器ArrayObject implements ArrayAccess so you can simply access them with the regular Array Notation, e.g.
In addition, ArrayObjects are IteratorAggregates, so you can iterate over them with
foreach
and decorate them with any of the SPL iterators, including the RecursiveIteratorIterator