Retrieve the key value from a arrayObject
This is my array:
ArrayObject::__set_state(
array( 'data' =>
array (
'key1' =&开发者_开发百科gt; '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.
ArrayObject implements ArrayAccess so you can simply access them with the regular Array Notation, e.g.
echo $arrayObject['key1'];
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
精彩评论