note 68602 added to function.array-push

From: Date: Thu, 03 Aug 2006 08:04:53 +0000
Subject: note 68602 added to function.array-push
Groups: php.notes 
Request: Send a blank email to php-notes+get-115505@lists.php.net to get a copy of this message
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); } } ?> ---- Server IP: 194.109.193.119 Probable Submitter: 193.173.22.130 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.array-push.php Edit -- https://master.php.net/note/edit/68602 Del: integrated -- https://master.php.net/note/delete/68602/integrated Del: useless -- https://master.php.net/note/delete/68602/useless Del: bad code -- https://master.php.net/note/delete/68602/bad+code Del: spam -- https://master.php.net/note/delete/68602/spam Del: non-english -- https://master.php.net/note/delete/68602/non-english Del: in docs -- https://master.php.net/note/delete/68602/in+docs Del: other reasons-- https://master.php.net/note/delete/68602 Reject -- https://master.php.net/note/reject/68602 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115505) next »