"Mark Cain" <[EMAIL PROTECTED]> wrote in message 
9cufuv$s20$[EMAIL PROTECTED]">news:9cufuv$s20$[EMAIL PROTECTED]...
> 
> Two things:
> 1) Why does the code below produce this result?
> 2) How do I assign to an multidimensional array with dynamic keys?
> 
> Here is the test code:
> 
> $first = "Elementary";
> $second = "Middle";
> 
> echo "before assignment:<BR>";
> echo "first = $first<BR>";    // prints: first = Elementary
> echo "second = $second<P>";   // prints: second = Middle   --- looks as
> expected here
> 
> 

look, before the assignment:

0. both $first and $second are string-type variables.

> $first[$second] = "pass";

1. In this case the brackets mean to index a character of the string (like in C), but 
2. $second is converted into int because of using as a string-index,
    the integer value of $second ("Middle") equals to 0. (how can you convert it in 
any other way?)
3. Things getting clearer... the your assignment says:
    - the 1st character of string $first let be "pass", 
there is no room any other character, but "p". (because of PHP think you'd like to 
change the 1st char only.)
4. so: "Elementary" ---> "plementary"
> 
> 
> echo "After Assignment:<BR>";
> echo "first = $first<BR>";    // prints: first = plementary   ---  what is
> this ????!!
> echo "second = $second<BR>";  // prints: second = Middle
> echo "$first[$second]";    // prints: P

what you want is the following - i think (i'm not familiar with perl at all):

$first = array($first, $second); what this produces is can be tested with 
var_dump($first) not with echo, by the way
var_dump($first);

This is a one-dimensional array with two entries.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to