Re: arrays as object properties

From: Date: Thu, 26 Oct 2000 09:59:21 +0000
Subject: Re: arrays as object properties
Groups: php.general 
Request: Send a blank email to php-general+get-22100@lists.php.net to get a copy of this message
Hi, Dallas.... $parts[]; is not necessary..... what i think she wants to do is, see what the output is hence... it has to be ... for ($i = 0; $i < sizeof($car->parts); $i++) { echo $car->parts[$i]."\n"; } i think $parts[]; won't make a difference..... but anyway! --- Dallas Kropka <dallask@firstworld.net> wrote: > First you need a constructor for your class > (function with the same name as > the class) > > > class car > { > var $parts[]; > function car($new_parts) > { > $this->parts = $new_parts; > } > } > > in your code > > $parts = array("radio","four_w_drive","mats","si"); > $car = new car($parts); > > > the $car = new car($parts) Line will (should) send > the array to the > constructor and set your array. > > I havent tested that, and some syntax could be > off... but it should work. > > NOTE: if I am off in my syntax, anyone feel free to > correct me. > > ----- Original Message ----- > From: "Rebecca" <rebecca@digitalpulp.com> > To: <php-general@lists.php.net> > Sent: Monday, October 23, 2000 10:29 AM > Subject: [PHP] arrays as object properties > > > > so if i have: > > > > class car { > > > > var $parts; > > > > function init($new_parts) { > > $this->parts = $new_parts; > > } > > } > > > > how can i make this work: > > > > $parts = > array("radio","four_w_drive","mats","si"); > > $car = new car; > > > > file://the following peice of code is the > trouble......i can't seem to > make an > > object property an array.... > > $car->init($parts); > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: > php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: > php-general-help@lists.php.net > > To contact the list administrators, e-mail: > php-list-admin@lists.php.net > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: > php-general-unsubscribe@lists.php.net > For additional commands, e-mail: > php-general-help@lists.php.net > To contact the list administrators, e-mail: > php-list-admin@lists.php.net > ===== To Find Out More About Me : http://mukul.tsx.org/ __________________________________________________ Do You Yahoo!? Yahoo! Messenger - Talk while you surf! It's FREE. http://im.yahoo.com/

« previous php.general (#22100) next »