RE: [PHP] classes - multidimensional arrays

From: Date: Fri, 27 Oct 2000 09:09:15 +0000
Subject: RE: [PHP] classes - multidimensional arrays
Groups: php.general 
Request: Send a blank email to php-general+get-22299@lists.php.net to get a copy of this message
---------------------------------------------------------------------------- ----------------- Disclaimer: The information contained in this email is intended only for the use of the person(s) to whom it is addressed and may be confidential or contain legally privileged information. If you are not the intended recipient you are hereby notified that any perusal, use, distribution, copying or disclosure is strictly prohibited. If you have received this email in error please immediately advise us by return email at postmaster@normandy.com.au and delete the email document without making a copy. ---------------------------------------------------------------------------- ----------------- Rebecca, Attached is a simple example of what you want. A couple of things; 1. I suggest you use the following format for your arrays as it's easier to read $addons[1]["price"] = 150; $addons[1]["description"] = "Base Level Radio Player Model 12.12A"; $addons[1]["cassete"] = "No"; $addons[1]["cd"] = "No"; $addons[2]["price"] = 4500; $addons[2]["description"] = "Racing Tyres"; $addons[2]["colour"] = "Black"; $addons[3]["price"] = 81245; $addons[3]["description"] = "Strpes to make your car go-faster"; $addons[3]["colour"] = "Red"; I find this is easier on the eye than those nasty nested array() statements.. yuck! You can then think of your 2d array like a table from a database.. or you can easily set your data from a db. 2. For true false statements use TRUE or FALSE instead of "Yes" and "No" The problem with Yes and No is that if($test == "Yes") will return false if $test = "yes"... 3. In a class/object you can sling around whatever you want. Strings, Numbers 2D Arrays, even other objects like $myYard = new Yard(); $myYard->cars[1] = new Car(); . . . $myYard->cars[1]->PrintQuote(); 4. If you have a init() type of method try using the constructor to define these (not appropriate in your example but look into it) Have fun. mn -----Original Message----- From: Mukul Sabharwal [mailto:mukulsabharwal@yahoo.com] Sent: Friday, October 27, 2000 12:25 PM To: Rebecca; php-general@lists.php.net Subject: Re: [PHP] classes - multidimensional arrays Rebecca, What's wrong in this, it works perfectly... if you access $transams->enhancements it will simply print 'Array' you'll have to traverse through the keys and values! Got it ? --- Rebecca <rebecca@digitalpulp.com> wrote: > ok - so what i meant was i want to use a > multidimensional array: > > class car { > > var $enhancements; > > function init($x) { > $this->enhancements = $x; > } > } > > $addons = array( > "radio" => array ( > "price" => > 150, > "cassete" > => "No", > "cd" => > "yes" > ), > "four_w_drive" => 1000, > "leather" => array ( > "price" > => 1200, > "color" > => "red", > > "stitching" => "blue" > ) > ); > > $transam = new car; > $transam->init($addons); > ===== 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 (#22299) next »