PHP class returning data one by one

Prototyping for a class returning items one by one

<?php

class printer
{
 function printer() {
 $in = new data();
   while($line = $in->getNext()) {
   echo $line;
   echo "\n";
 }
 return;
 }
}

class data
{
 function __construct()
 {
  $this->i = 0;
 }

 function getNext()
 {
 $dat =  array(1,2,3,4,5,6,7,8);
 if($this->i < count($dat)) {
 return $dat[$this->i++];
 }
 else {
 return FALSE;
 }
 }
}

$out = new printer();
$out->printer();
exit;
?>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.