Reply to Re: Why does this array result occur?

Your name:

Reply:


Posted by Koncept on 11/02/06 21:25

In article <Fzs2h.252$AR2.105@newsfe04.lga>, Steve <no.one@example.com>
wrote:

> | <?php
> | $test['k1']['k2'] = 'hello';
> | $test['k1']['k2']['k3'] = 'world';
> |
> | /*
> | Array
> | (
> | [k1] => Array
> | (
> | [k2] => wello
> | )
> |
> | )
> | */
> | ?>
>
> you are forcing to treat the string "hello" as an array...and php is mixing up the
> hash for k2 when retrieving it as a result.

Labelled as "poor programming" or not, I am only interested in
understanding why this is happening based on the code provided.

If I were forcing to treat the string "hello" as an array, wouldn't php
be kind enough to automagically create an index of 0 for this value in
[k1][k2], or at the least, throw up a nice juicy warning telling me
that I'm an idiot for trying to kick it in the nuts?

$test[] = "hello"; // would create an automatic index of 0 for the
value "hello"

What I expected (at the very least) is that k2 would be preserved as
"hello" at index 0, while all other keys and values of the $test hash
would be ignored. How come the first character of k3's value is
maintained, yet at the same time, overwritten with characters one
onwards from string k2?

I still don't follow the process. How *exactly* is PHP mixing up the
process?

--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация