Re: A problem with associative arrays..
| From: | Rasmus Lerdorf | Date: | Wed, 26 Jul 2000 20:30:49 +0000 |
| Subject: | Re: A problem with associative arrays.. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-8403@lists.php.net to get a copy of this message | ||
Ah right. This is a known limitation. Just like you can't do:
$a = 'abc';
$a[1] = 'def';
Once $a is defined to be a string, then $a[1] is an offset into that
string array.
-Rasmus
On Wed, 26 Jul 2000, Warren Vanichuk wrote:
> On Wed, 26 Jul 2000, Rasmus Lerdorf wrote:
>
> > Put single quotes around your array indices.
>
> That was my original code, same results.
>
> Code is now:
>
> <?php
>
>
>
> $conf['db'] = "testdb";
> $conf['db']['host'] = "dbhost";
>
> echo "value is: " . $conf['db'] . "<br>";
> echo "host is: " . $conf['db']['host'] . "<br>";
>
> $conf['db'] = "dbtest";
> $conf['db']['host'] = "hostdb";
>
> echo "value is now : " . $conf['db'] . "<br>";
> echo "host is now : " . $conf['db']['host'] .
> "<br>";
>
> php?>
>
> Result is now:
>
> value is: destdb
> host is: d
> value is now : tbtest
> host is now : t
>
> > -Rasmus
> >
> > On Wed, 26 Jul 2000, Warren Vanichuk wrote:
> >
> > >
> > > Ok, I have just discovered that I cannot mix 'dimensions' in an associative
> > > array.
> > >
> > > The source I have :
> > >
> > > <?php
> > >
> > > $conf[db] = "bazfoobar";
> > > $conf[db][host] = "thishost";
> > >
> > > echo "value is: " . $conf[db] . "<br>";
> > > echo "host is: " . $conf[db][host] . "<br>";
> > >
> > > $conf[db] = "foobarbaz";
> > > $conf[db][host] = "somehost";
> > >
> > > echo "value is now : " . $conf[db] . "<br>";
> > > echo "host is now : " . $conf[db][host] . "<br>";
> > >
> > > php?>
> > >
> > >
> > > Generates :
> > >
> > > value is: tazfoobar
> > > host is: t
> > > value is now : soobarbaz
> > > host is now : s
> > >
> > > Is this expected behaviour in PHP3? Can I actually do this in PHP4? Do I
> > > have to ensure that all of my associative arrays have the exact same
> > > dimensions?
> > >
> > > Suggestions? Hints? Valium? :)
> > >
> > > TIA.. :)
> > >
> > > Sincerely, Warren
> > >
> > >
> > >
> >
> >
> >
>
>