RE: [PHP] trouble with each() list() and array()

From: Date: Tue, 21 Nov 2000 10:08:59 +0000
Subject: RE: [PHP] trouble with each() list() and array()
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-26503@lists.php.net to get a copy of this message
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.

« previous php.general (#26503) next »