note 68602 deleted from function.array-push by googleguy

From: Date: Tue, 22 Oct 2013 14:58:45 +0000
Subject: note 68602 deleted from function.array-push by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197263@lists.php.net to get a copy of this message
Note Submitter: antido at gmail dot com ---- Simple data object implementation: <?php /** * Data object * * @version 0.6 * @author Tom Reitsma <antido@gmail.com> */ Class DataObject { /** * @var int $ptr */ private $ptr = 0; /** * @var array $data */ private $data = array(); /** * Class constructor */ public function __construct($anArray=false) { if($anArray != false) { if(is_array($anArray)) { $this->data[] = $anArray; } } } /** * Fetches the data under the pointer * * @return String if there is still data left under the pointer, false if the end has been reached */ public function fetch() { if(isset($this->data[$this->ptr])) { return $this->data[$this->ptr++]; } return false; } /** * Moves to the next row in the data object * * @return boolean */ public function moveNext() { $newPtr = $this->ptr + 1; if(isset($this->data[$newPtr])) { $this->ptr = $newPtr; return true; } return false; } /** * Moves to the previous row in the data object * * @return boolean */ public function movePrevious() { $newPtr = $this->ptr - 1; if(isset($this->data[$newPtr])) { return $this->data[$newPtr]; } return false; } /** * Pushes an element onto the array * * @param String or an array $input * @return number of elements */ public function push($input) { if($this->getNumRows() > 0) { return array_push($this->data, $input); } else { return $this->data[] = $input; } } /** * Counts the number of rows */ public function getNumRows() { return count($this->data); } } ?>

« previous php.notes (#197263) next »