fork download
  1. <?php
  2. class Animal {
  3.  
  4. }
  5.  
  6. $dog = new Animal();
  7. $cat = new Animal();
  8. $mouse = new Animal();
  9.  
  10. $spl = new SplObjectStorage();
  11.  
  12. $spl->attach($dog);
  13. $spl->attach($cat);
  14. $spl->attach($mouse);
  15.  
  16. foreach ($spl as $a) {
  17. echo "Outer start\n";
  18.  
  19. foreach ($spl as $b) {
  20. echo "Inner\n";
  21. }
  22.  
  23. echo "Outer end\n";
  24. }
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
Outer start
Inner
Inner
Inner
Outer end