Re: RecursiveArrayIterator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 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?


<?php
$array = array(
    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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux