note 87666 modified in language.types.resource by danbrown

From: Date: Tue, 16 Dec 2008 17:24:11 +0000
Subject: note 87666 modified in language.types.resource by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-148222@lists.php.net to get a copy of this message
Resources are commonly used to iterate through a mysql or file handle. example <?php while($row = mysql_fetch_row($resource)){ echo $row[0] ; } ?> It's possible to fake this treatment. <?php class fakewhile{ public $arrayCount; public $arrayCounter; function setArrValues(){ $this->arrValues = array(0 =>array("apple","artichoke","apricot"),1 => array("bears","dogs","cats")); $this->arrayCounter = 0; $this->arrayCount = count($this->arrValues); } function outputValues(){ /* * Anything until the if statement is evaluted one more * time then the array count value */ $arrayInfo = $this->arrValues; $arrCounter = $this->arrayCounter; if($arrCounter > $this->arrayCount){ return false; } $endCounter = $arrCounter+1; $this->arrayCounter = $endCounter; return $arrayInfo[$arrCounter]; } } $fw = new fakewhile(); $fw->setArrValues(); while($row = $fw->outputValues()){ print_r($row); } ?> Hopefully will get someone started on completing a complete application. --was-- Resources are commonly used to iterate through a mysql or file handle. example while($row = mysql_fetch_row($resource)){ echo $row[0] ; } It's possible to fake this treatment. class fakewhile{ public $arrayCount; public $arrayCounter; function setArrValues(){ $this->arrValues = array(0 =>array("apple","artichoke","apricot"),1 => array("bears","dogs","cats")); $this->arrayCounter = 0; $this->arrayCount = count($this->arrValues); } function outputValues(){ /* * Anything until the if statement is evaluted one more * time then the array count value */ $arrayInfo = $this->arrValues; $arrCounter = $this->arrayCounter; if($arrCounter > $this->arrayCount){ return false; } $endCounter = $arrCounter+1; $this->arrayCounter = $endCounter; return $arrayInfo[$arrCounter]; } } $fw = new fakewhile(); $fw->setArrValues(); while($row = $fw->outputValues()){ print_r($row); } Hopefully will get someone started on completing a complete application. http://php.net/manual/en/language.types.resource.php

« previous php.notes (#148222) next »