I tried to wrote a custom array iterator with PHP's factory class. My problem: I need all array's all datas, example, here is a simple PHP array:
Array
(
[authentication] => Array
(
[basic] => Array
(
[username] => guest
[password] => guest
)
[filters] => Array
(
[price] => 100
[owener] => me
)
)
)
I see on PHP's doc page, I can use two simple class and iterate with simple foreach:
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->phpArray));
foreach($iterator as $key => $value) {
$d = $iterator->getDepth();
echo "depth: $d $key => $value\n";
}
This program throw following output:
depth: 2 key: username, value: guest
depth: 2 key: password, value: guest
depth: 2 key: price, value: 100
depth: 2 key: owener, value: me
How to modify my code what can do a following example output with all datas:
depth: 0 key: authentication, value:
depth: 1 key: basic, value:
depth: 1 key: filters,
depth: 2 key: username, value: guest
depth: 2 key: password, value: guest
depth: 2 key: price, value: 100
depth: 2 key: owener, value: me
Thank you!