|
Posted by Steve on 11/02/06 20:31
"Koncept" <user@unknown.invalid> wrote in message
news:021120061435509881%user@unknown.invalid...
|
| I just ran a small test out of curiosity to see what would happen and I
| must say that I am surprised at the result. Can anybody explain to me
| why this code returns what it does? Does it make sense or is this a
| bug?
|
| <?php
| $test['k1']['k2'] = 'hello';
| $test['k1']['k2']['k3'] = 'world';
|
| /*
| Array
| (
| [k1] => Array
| (
| [k2] => wello
| )
|
| )
| */
| ?>
in php, and c-style languages, a string is treated like an array of
characters. also in php, arrays are really just data in a hash. what has
happened is that, through poor programming (sorry to offend), 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.
i could go under-the-hood but most of that explanation would be lost on
those here, i think.
| "The snake that cannot shed its skin perishes. So do the spirits who are
| prevented from changing their opinions; they cease to be a
pirit." -Nietzsche
"The flower who lost it's stamen must no longer be a flower; just as the
cameleon who is prevented from changing its color must no longer be a
cameleon." - spiritual apple
Navigation:
[Reply to this message]
|