note 67605 deleted from ref.array by bjori

From: Date: Thu, 08 Jun 2006 23:59:34 +0000
Subject: note 67605 deleted from ref.array by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-113972@lists.php.net to get a copy of this message
Note Submitter: egoncasteel at gmail dot com Reason: useless ---- here is an example of how to use an array of objects in a class. This is an example, but i am using it to store differnt types of vars with there valadation and display functions. <?php class car{ public $size; function __construct($foo){ $this->size = $foo; } public function horn(){ return $this->size." car gos honk"; } } class traffic{ public $cars = array(); function __construct(){ $this->cars['big'] = new car('big'); $this->cars['small'] = new car('small'); $this->cars['compact'] = new car('compact'); $this->cars['road_hog'] = new car('road hog'); } public function jam(){ foreach($this->cars as $car){ $output .= $car->horn().'<br />'; } return $output; } } $traffic = new traffic; echo $traffic->jam(); echo '<br /><br />'; echo 'single call test '.$traffic->cars['big']->horn(); ?>

« previous php.notes (#113972) next »