RE: [PHP] A problem with associative arrays..

From: Date: Wed, 26 Jul 2000 21:17:24 +0000
Subject: RE: [PHP] A problem with associative arrays..
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-8410@lists.php.net to get a copy of this message
On Wed, 26 Jul 2000, Rasmus Lerdorf wrote: > > Woah! PHP can do this? Since what version? As far as I knew, > > you needed to use substr() to get even 1 character from a string. > > This is too cool. > > Since forever. This was added to the early days of PHP 3 > > > > > $conf['db'] = "testdb"; > > > > $conf['db']['host'] = "dbhost"; > > > > He's not defining it as a string. He's accessing it as an array. > > Does it still apply? What if he defined $conf to be an array > > prior to this? > > Think of it this way: > > $conf['db'] = "testdb"; > > Now, when you try to assign something to $conf['db']['host'] the > $conf['db'] part is "testdb", what would > "testdb"['host'] be? Since > $cond['db'] is a string, the 'host' index of this string is the same as > "testdb"[0] which is the first position of the string. So when you do: > > $conf['db']['host'] = "dbhost"; > > You end up with, "destdb", because there is only room for the first > character of "dbhost" in the $conf['db'][0] slot. Thank for you for the explanation. Now that I understand how PHP is parsing this, I realize the error of my ways. It's my Perl experience leaking through again. :) I guess I just have to fix up a work around to this. :) Thanks again! :) Sincerely, Warren

« previous php.general (#8410) next »