RE: I don't get arrays! HELP ME PLEASE!

From: Date: Wed, 22 Nov 2000 02:08:19 +0000
Subject: RE: I don't get arrays! HELP ME PLEASE!
Groups: php.general 
Request: Send a blank email to php-general+get-26565@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. ---------------------------------------------------------------------------- ----------------- Since 2d arrays are just arrays of arrays why not $row["name"]="John"; $row["email"]="john@domain.com"; $friends[] = $row; $row["name"]="Mary"; $row["email"]="mary@anotherdomain.com"; $friends[] = $row; See how easy this would be to put in a while statement? Also whilst creating new members of an array is simple with [] you should try to make the key something usful and of course unquie $customerid = 12345678; $row["name"]="John"; $row["email"]="john@domain.com"; $customers[$customerid] = $row; This way when you have an order that specifies a customer id you can easily find it in your 2d array. by $customerid = 12345678; $row = $customers[$customerid]; $name = $row["name"]; $email = $row["email"]; mn Mark Nold markn@enspace.com <mailto:markn@enspace.com> Senior Consultant   Change is inevitable, except from vending machines. -----Original Message----- From: Christian Dechery [mailto:lemming@vento.com.br] Sent: Wednesday, November 22, 2000 4:30 AM To: MR Cc: php-general@lists.php.net Subject: I don't get arrays! HELP ME PLEASE! At 11:08 21/11/00 +0100, you wrote: >Christian Dechery ... > > > > >Just make multi-dimensioned arrays, like this for example... > > > > > >$friends[1][name]="John"; > > >$friends[1][email]="john@domain.com"; > > > > > >$friends[2][name]="Mary"; > > >$friends[2][email]="mary@anotherdomain.com"; > > > > cool... so If I want to feed a list I can just do that: > > > > while(fgets($str,lenght,file)) > > { > > code ... break $str ... code... > > $friends[][name]=$name; > > $friends[][email]=$email; > > } > > > > right? > >NO!! > >That would generate the following: > >$friends[1][name]=John >$friends[2][email]=john@domain.com >$friends[3][name]=mary >$friends[4][email]=mary@anotherdomain.com > >Every time that you use [], a new element is created into the array!!! > >But if you use the other array i purposed, first email or name and then >the number: > >$friends[name][] =$name >$friends[email][]=$email > >That should work, as every time you do [], you do it in two separate >arrays... with [] you allocate space for a new name, then for a >new email... > >In the former example, you were allocating space for a new friend... > > > and I should forget about structs and start using DBs? After all that's > > what DBs are for. > > cutting to the chase... there are no pointers in PHP, no structs. And this > > is due it's ease to deal with DBs, correct? > >Yeah. Using DBs in PHP is also pretty simple. I didn't know anything about >SQL databases two months ago, and now i'm working with an >impressive oracle8 database with more than 60 tables!! > >Dealing with databases is pretty simple. Connect to the database with ONE >LINE of code, execute an statement with TWO LINES, and >fetch the next record with ONE LINE of code... > >Every time i look at the code of a Java Servlet that deals with databases >i can't help laughing... 5 lines to connect and instance a >connection and an alias, another 4 or 5 to execute an statement, another 3 >to fetch the next record... > >And of course, in Java you don't have that readable 20-chars-long lines of >code... you have: > >document.all.layers.all.form1.inputbox.content = document.all.layers.all >...... > >and so on. I hate Java anyway. ok... got it! You know what my real problem is? Addiction to C and it's nasty thousands of lines to do something simple. Like, I didn't get REALLY what that command array() is for. What can u do with it? Create and fill up a hash table? With what? for instance (I know I'm being a pain in the ass, just tell me when to stop and I will)... I created in pure C a pseudo-e-commerce system for my website. Since we don't have databases (lack of cash) I did it all with binary files. It works fine... perfect. And I have a logfile so I can create stats. It is in the format: product_id|product_name|time|boolean type(can be 1 or 0, 1 for click, 0 for view) ok? and I had to make a nice and cool log analyzer for the "clients" so they can view how their products are going. So I went there created structs, lists and tables in memory to store all the shit I needed and then put it out on nice and kewl templates... and I have NO idea how to build lists and tables on PHP... this array stuff isn't really giving me what I need. Or it does, but I can't see it. All the examples I've seen tells me nothing. and that is a low-to-medium complexity code, so I tought, if I could get that "translated" to PHP, than I'd undestand those DAMNED arrays... you know? I'm a pointer freak. I don't see three or four varibles coming from one function without pointers. sorry once again... I don't know anyone who programs in PHP, they all say: "PHP? Humpf... ASP rules.", and getting started from a manual isn't easy at all. ____________________________ . Christian Dechery (lemming) . http://www.tanamesa.com.br . Gaita-L Owner / Web Developer

« previous php.general (#26565) next »