@ 2012-11-25T20:11:47Z <?php
// extend the RecursiveIteratorIterator
class ULRows extends RecursiveIteratorIterator {
function __construct($it) {
// here we use the parent class and use LEAVES_ONLY to
parent::__construct($it, self::LEAVES_ONLY);
}
function beginChildren() {
echo '<ul>';
}
function endChildren() {
echo '</ul>' . "\n";
}
}
/**
* * an array of animal **
*/
$animals = array(
array('type' => 'dog','name' => 'butch','sex' => 'm','breed' => 'boxer'),
array('type' => 'dog','name' => 'fido','sex' => 'm','breed' => 'doberman'),
array('type' => 'dog','name' => 'girly','sex' => 'f','breed' => 'poodle'),
array('type' => 'cat','name' => 'tiddles','sex' => 'm','breed' => 'ragdoll'),
array('type' => 'cat','name' => 'tiddles','sex' => 'f','breed' => 'manx'),
array('type' => 'cat','name' => 'tiddles','sex' => 'm','breed' => 'maine coon'),
array('type' => 'horse','name' => 'ed','sex' => 'm','breed' => 'clydesdale'),
array('type' => 'perl_coder','name' => 'shadda','sex' => 'none','breed' => 'mongrel'),
array('type' => 'duck','name' => 'galapogus','sex' => 'm','breed' => 'pekin'));
/**
* * create a new recursive array iterator **
*/
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator(new ArrayIterator($animals)));
/**
* * traverse the $iterator object **
*/
while ( $iterator->valid() ) {
var_dump($iterator->current());
echo "<li>" . $iterator->current() . '</li>';
$iterator->next();
}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Deprecated: Return type of ULRows::beginChildren() should either be compatible with RecursiveIteratorIterator::beginChildren(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/jj1Rh on line 11
Deprecated: Return type of ULRows::endChildren() should either be compatible with RecursiveIteratorIterator::endChildren(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/jj1Rh on line 15
array(4) {
["type"]=>
string(3) "dog"
["name"]=>
string(5) "butch"
["sex"]=>
string(1) "m"
["breed"]=>
string(5) "boxer"
}
Warning: Array to string conversion in /in/jj1Rh on line 44
<li>Array</li>string(3) "dog"
<li>dog</li>string(5) "butch"
<li>butch</li>string(1) "m"
<li>m</li>string(5) "boxer"
<li>boxer</li>string(3) "dog"
<li>dog</li>string(4) "fido"
<li>fido</li>string(1) "m"
<li>m</li>string(8) "doberman"
<li>doberman</li>string(3) "dog"
<li>dog</li>string(5) "girly"
<li>girly</li>string(1) "f"
<li>f</li>string(6) "poodle"
<li>poodle</li>string(3) "cat"
<li>cat</li>string(7) "tiddles"
<li>tiddles</li>string(1) "m"
<li>m</li>string(7) "ragdoll"
<li>ragdoll</li>string(3) "cat"
<li>cat</li>string(7) "tiddles"
<li>tiddles</li>string(1) "f"
<li>f</li>string(4) "manx"
<li>manx</li>string(3) "cat"
<li>cat</li>string(7) "tiddles"
<li>tiddles</li>string(1) "m"
<li>m</li>string(10) "maine coon"
<li>maine coon</li>string(5) "horse"
<li>horse</li>string(2) "ed"
<li>ed</li>string(1) "m"
<li>m</li>string(10) "clydesdale"
<li>clydesdale</li>string(10) "perl_coder"
<li>perl_coder</li>string(6) "shadda"
<li>shadda</li>string(4) "none"
<li>none</li>string(7) "mongrel"
<li>mongrel</li>string(4) "duck"
<li>duck</li>string(9) "galapogus"
<li>galapogus</li>string(1) "m"
<li>m</li>string(5) "pekin"
<li>pekin</li> Output for 8.0.0 - 8.0.30 array(4) {
["type"]=>
string(3) "dog"
["name"]=>
string(5) "butch"
["sex"]=>
string(1) "m"
["breed"]=>
string(5) "boxer"
}
Warning: Array to string conversion in /in/jj1Rh on line 44
<li>Array</li>string(3) "dog"
<li>dog</li>string(5) "butch"
<li>butch</li>string(1) "m"
<li>m</li>string(5) "boxer"
<li>boxer</li>string(3) "dog"
<li>dog</li>string(4) "fido"
<li>fido</li>string(1) "m"
<li>m</li>string(8) "doberman"
<li>doberman</li>string(3) "dog"
<li>dog</li>string(5) "girly"
<li>girly</li>string(1) "f"
<li>f</li>string(6) "poodle"
<li>poodle</li>string(3) "cat"
<li>cat</li>string(7) "tiddles"
<li>tiddles</li>string(1) "m"
<li>m</li>string(7) "ragdoll"
<li>ragdoll</li>string(3) "cat"
<li>cat</li>string(7) "tiddles"
<li>tiddles</li>string(1) "f"
<li>f</li>string(4) "manx"
<li>manx</li>string(3) "cat"
<li>cat</li>string(7) "tiddles"
<li>tiddles</li>string(1) "m"
<li>m</li>string(10) "maine coon"
<li>maine coon</li>string(5) "horse"
<li>horse</li>string(2) "ed"
<li>ed</li>string(1) "m"
<li>m</li>string(10) "clydesdale"
<li>clydesdale</li>string(10) "perl_coder"
<li>perl_coder</li>string(6) "shadda"
<li>shadda</li>string(4) "none"
<li>none</li>string(7) "mongrel"
<li>mongrel</li>string(4) "duck"
<li>duck</li>string(9) "galapogus"
<li>galapogus</li>string(1) "m"
<li>m</li>string(5) "pekin"
<li>pekin</li> Output for 5.4.0 - 5.4.45 , 5.5.0 - 5.5.37 , 5.6.0 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.33 , 7.2.6 - 7.2.33 , 7.3.0 - 7.3.31 , 7.4.0 - 7.4.33 array(4) {
["type"]=>
string(3) "dog"
["name"]=>
string(5) "butch"
["sex"]=>
string(1) "m"
["breed"]=>
string(5) "boxer"
}
Notice: Array to string conversion in /in/jj1Rh on line 44
<li>Array</li>string(3) "dog"
<li>dog</li>string(5) "butch"
<li>butch</li>string(1) "m"
<li>m</li>string(5) "boxer"
<li>boxer</li>string(3) "dog"
<li>dog</li>string(4) "fido"
<li>fido</li>string(1) "m"
<li>m</li>string(8) "doberman"
<li>doberman</li>string(3) "dog"
<li>dog</li>string(5) "girly"
<li>girly</li>string(1) "f"
<li>f</li>string(6) "poodle"
<li>poodle</li>string(3) "cat"
<li>cat</li>string(7) "tiddles"
<li>tiddles</li>string(1) "m"
<li>m</li>string(7) "ragdoll"
<li>ragdoll</li>string(3) "cat"
<li>cat</li>string(7) "tiddles"
<li>tiddles</li>string(1) "f"
<li>f</li>string(4) "manx"
<li>manx</li>string(3) "cat"
<li>cat</li>string(7) "tiddles"
<li>tiddles</li>string(1) "m"
<li>m</li>string(10) "maine coon"
<li>maine coon</li>string(5) "horse"
<li>horse</li>string(2) "ed"
<li>ed</li>string(1) "m"
<li>m</li>string(10) "clydesdale"
<li>clydesdale</li>string(10) "perl_coder"
<li>perl_coder</li>string(6) "shadda"
<li>shadda</li>string(4) "none"
<li>none</li>string(7) "mongrel"
<li>mongrel</li>string(4) "duck"
<li>duck</li>string(9) "galapogus"
<li>galapogus</li>string(1) "m"
<li>m</li>string(5) "pekin"
<li>pekin</li> Output for 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 , 7.3.32 - 7.3.33 array(4) {
["type"]=>
string(3) "dog"
["name"]=>
string(5) "butch"
["sex"]=>
string(1) "m"
["breed"]=>
string(5) "boxer"
}
<li>Array</li>string(3) "dog"
<li>dog</li>string(5) "butch"
<li>butch</li>string(1) "m"
<li>m</li>string(5) "boxer"
<li>boxer</li>string(3) "dog"
<li>dog</li>string(4) "fido"
<li>fido</li>string(1) "m"
<li>m</li>string(8) "doberman"
<li>doberman</li>string(3) "dog"
<li>dog</li>string(5) "girly"
<li>girly</li>string(1) "f"
<li>f</li>string(6) "poodle"
<li>poodle</li>string(3) "cat"
<li>cat</li>string(7) "tiddles"
<li>tiddles</li>string(1) "m"
<li>m</li>string(7) "ragdoll"
<li>ragdoll</li>string(3) "cat"
<li>cat</li>string(7) "tiddles"
<li>tiddles</li>string(1) "f"
<li>f</li>string(4) "manx"
<li>manx</li>string(3) "cat"
<li>cat</li>string(7) "tiddles"
<li>tiddles</li>string(1) "m"
<li>m</li>string(10) "maine coon"
<li>maine coon</li>string(5) "horse"
<li>horse</li>string(2) "ed"
<li>ed</li>string(1) "m"
<li>m</li>string(10) "clydesdale"
<li>clydesdale</li>string(10) "perl_coder"
<li>perl_coder</li>string(6) "shadda"
<li>shadda</li>string(4) "none"
<li>none</li>string(7) "mongrel"
<li>mongrel</li>string(4) "duck"
<li>duck</li>string(9) "galapogus"
<li>galapogus</li>string(1) "m"
<li>m</li>string(5) "pekin"
<li>pekin</li> Output for 5.0.0 - 5.0.5 Fatal error: Class 'RecursiveArrayIterator' not found in /in/jj1Rh on line 37
Process exited with code 255 . Output for 4.4.2 - 4.4.9 Parse error: syntax error, unexpected ')', expecting '(' in /in/jj1Rh on line 8
Process exited with code 255 . Output for 4.3.0 - 4.3.1 , 4.3.5 - 4.3.11 , 4.4.0 - 4.4.1 Parse error: parse error, unexpected ')', expecting '(' in /in/jj1Rh on line 8
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Parse error: parse error, expecting `'('' in /in/jj1Rh on line 8
Process exited with code 255 . preferences:dark mode live preview
303.45 ms | 401 KiB | 378 Q