On Saturday 05 May 2001 16:55, Mark Cain wrote:

> In Perl I can assign dynamic keys ad infinitum to an array such as:
>
> $sku{$id}{$line}{$price} = 99;

Same in PHP:

$sku [$id] [$line] [$price] = 99;

if $sku is an array. If unsure, initialize it as one:
$sku = array ();

> Here is the test code:
>
> $first = "Elementary";
> $second = "Middle";

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

> echo "After Assignment:<BR>";
> echo "first = $first<BR>";    // prints: first = plementary   ---  what
> is this ????!!

$first is a string, i.e. $first [$n] accesses the $n'th character in the 
string "Elementary".
$second is a string as well. You use it as index in the string, so it is 
automatically converted to an integer: "Middle" -> 0

So you assign "pass" to the first character of $first.
And as you can only assign other single characters to a single char, the 
first char of "pass" is used.

> echo "$first[$second]";    // prints: P

That should be a lowercase 'p' (see above)


Summary: You thought too complex and thus stumbled over another feature 
of PHP :)

-- 
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

What luck for the rulers that men do not think.

- Adolf Hitler

--
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