Re: Array within a Class?

From: Date: Sat, 05 Jan 2002 23:59:25 +0000
Subject: Re: Array within a Class?
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-11318@lists.php.net to get a copy of this message
Mike, Yes, you can create and access an array within a class. I've written seveal classes using arrays and it works just fine: class Produce { var $Fruit = array(); function Produce() { // Access class variable $this->Fruit[] = "Oranges"; $this->Fruit[] = "Grapes"; } function More() { // Create and access local array $Vegies = array(); $Vegies[] = "Broccoli"; $Vegies[] = "Onions"; } } Michael Sims wrote: > > At 03:04 PM 1/5/2002 -0800, Chris Hall wrote: > >Just a quicky -- > > > >I have yet to see anyone define an array within a class, yet if it is > >possible, would i be able to access that array with > >$this->array["variable"];? > > I've designed a class that has a method that RETURNS an array, but it > sounds like you want to define one of the properties of your class as an > array, i.e.: > > class testObject { > > var $testarray = array("firstindex" => "firstvalue", > "secondindex" => "secondvalue"); > > ... > > } > > I haven't personally done this, but I can't see why it wouldn't be > possible. Then if you wanted to access it inside a method you should be > able to the way you have described, like: > > function testMethod () { > > return $this->testarray["firstindex"]; > } > > Should work....why don't you give it a shot and see what happens? :) > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net > For additional commands, e-mail: php-windows-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net -- Do you need a Web-based Content Publishing System ? Call me for more details. Ed Swartz ColdFusion and PHP Development 978.772.0888 http://www.sandypondconsulting.com

« previous php.windows (#11318) next »