Re: [PHP] RecursiveArrayIterator

2007-07-25 Thread Nathan Nobbe
as i said earlier the purpose of an iterator is to hide the internal representation of an object. ive been thinking about it the past couple of days and the odd thing with php is, well in php, the array construct is used to store almost everything complex. in java there are lots of different

Re: [PHP] RecursiveArrayIterator

2007-07-24 Thread Richard Lynch
On Sun, July 22, 2007 9:02 pm, Kevin Waterson wrote: This one time, at band camp, Nathan Nobbe [EMAIL PROTECTED] wrote: Thanks for the response. I was hoping to avoid this sort of recursion within userspace and keep it at a lower level. Should not the recursive iterator recurse so we dont

Re: [PHP] RecursiveArrayIterator

2007-07-23 Thread Kevin Waterson
This one time, at band camp, Jim Lucas [EMAIL PROTECTED] wrote: I don't get it, why not do this? foreach ( $array AS $row ) { foreach ( $row AS $k = $v ) { if ( ! is_array($v) ) { echo {$k} -- {$v}br/\n; } } } Maybe I am

Re: [PHP] RecursiveArrayIterator

2007-07-23 Thread Nathan Nobbe
the purpose of an iterator is to allow client code to access the various (aggregate) components of an object while concealing its underlying implementation. the client code only has to know about the iterators interface. thus 1 or more objects that all have a potentially different data profile

Re: [PHP] RecursiveArrayIterator

2007-07-23 Thread Larry Garfield
On Monday 23 July 2007, Kevin Waterson wrote: This one time, at band camp, Jim Lucas [EMAIL PROTECTED] wrote: I don't get it, why not do this? foreach ( $array AS $row ) { foreach ( $row AS $k = $v ) { if ( ! is_array($v) ) { echo {$k} -- {$v}br/\n;

Re: [PHP] RecursiveArrayIterator

2007-07-23 Thread Nathan Nobbe
On 7/23/07, Larry Garfield [EMAIL PROTECTED] wrote: Isn't that what garbage collection is for? well garbage collection will remove the copy of an array created by foreach, but what Kevin is saying is Iterators dont bother creating a copy of the array, which overall results in memory savings.

Re: [PHP] RecursiveArrayIterator

2007-07-23 Thread Robert Cummings
On Mon, 2007-07-23 at 10:39 -0400, Nathan Nobbe wrote: On 7/23/07, Larry Garfield [EMAIL PROTECTED] wrote: Isn't that what garbage collection is for? well garbage collection will remove the copy of an array created by foreach, but what Kevin is saying is Iterators dont bother creating a

[PHP] RecursiveArrayIterator

2007-07-22 Thread Kevin Waterson
When I run the code below, I get an output of the array which is good. But the first member of the array output is 0=Array. Is there a way to prevent this? eg: 0 -- Array name -- butch sex -- m breed -- boxer name -- fido sex -- m breed -- doberman name -- girly sex -- f breed -- poodle ?php

Re: [PHP] RecursiveArrayIterator

2007-07-22 Thread Nathan Nobbe
Kevin, im not sure why you need the RecursiveIteratorIterator; the RecursiveArrayIterator is capable of handling the nested arrays by itself. here is a revision of the code you posted, using PHP_EOL for newlines since i developed this via the CLI. ?php $array = array( array('name'='butch',

Re: [PHP] RecursiveArrayIterator

2007-07-22 Thread Kevin Waterson
This one time, at band camp, Nathan Nobbe [EMAIL PROTECTED] wrote: Thanks for the response. I was hoping to avoid this sort of recursion within userspace and keep it at a lower level. Should not the recursive iterator recurse so we dont need to be using user defined functions?

Re: [PHP] RecursiveArrayIterator

2007-07-22 Thread Kevin Waterson
This is what I have so far.. ?php $array = array( array('name'='butch', 'sex'='m', 'breed'='boxer'), array('name'='fido', 'sex'='m', 'breed'='doberman'), array('name'='girly','sex'='f', 'breed'='poodle') ); $iterator = new RecursiveIteratorIterator(new

Re: [PHP] RecursiveArrayIterator

2007-07-22 Thread Nathan Nobbe
there is no base case in the printArrayKeysRecursively method; therefore it is not handling recursion; its just using the RecursiveArrayItereators public methods. i think that is totally appropriate. but i believe i understand what youre getting at; namely the RecursiveArrayIterator implments

Re: [PHP] RecursiveArrayIterator

2007-07-22 Thread Jim Lucas
Kevin Waterson wrote: This is what I have so far.. ?php $array = array( array('name'='butch', 'sex'='m', 'breed'='boxer'), array('name'='fido', 'sex'='m', 'breed'='doberman'), array('name'='girly','sex'='f', 'breed'='poodle') ); $iterator = new RecursiveIteratorIterator(new