Re: RecursiveArrayIterator
| From: | Jim Lucas | Date: | Mon, 23 Jul 2007 04:02:14 +0000 |
| Subject: | Re: RecursiveArrayIterator | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-259354@lists.php.net to get a copy of this message | ||
Kevin Waterson wrote:
This is what I have so far.. <?php $array = array(<?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 RecursiveArrayIterator($array)); while($iterator->valid()){ if(!$iterator->hasChildren()) { echo $iterator->key().' -- '.$iterator->current().'<br/>'; } $iterator->next(); }?> Kevin I don't get it, why not do this?
array('name'=>'butch', 'sex'=>'m', 'breed'=>'boxer'),
array('name'=>'fido', 'sex'=>'m', 'breed'=>'doberman'),
array('name'=>'girly','sex'=>'f', 'breed'=>'poodle')
);
foreach ( $array AS $row ) {
foreach ( $row AS $k => $v ) {
if ( ! is_array($v) ) {
echo "{$k} -- {$v}<br/>\n";
}
}
}
?>
This seems like a few less lines of code
Maybe I am missing the point... ???
Jim Lucas