note 67605 added to ref.array
| From: | egoncasteel at gmail dot com | Date: | Thu, 08 Jun 2006 23:25:56 +0000 |
| Subject: | note 67605 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-113959@lists.php.net to get a copy of this message | ||
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();
?>
----
Server IP: 216.194.113.175
Probable Submitter: 64.73.76.107
----
X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit -- http://master.php.net/note/edit/67605
Del: integrated -- http://master.php.net/note/delete/67605/integrated
Del: useless -- http://master.php.net/note/delete/67605/useless
Del: bad code -- http://master.php.net/note/delete/67605/bad+code
Del: spam -- http://master.php.net/note/delete/67605/spam
Del: non-english -- http://master.php.net/note/delete/67605/non-english
Del: in docs -- http://master.php.net/note/delete/67605/in+docs
Del: other reasons-- http://master.php.net/note/delete/67605
Reject -- http://master.php.net/note/reject/67605
Search -- http://master.php.net/manage/user-notes.php