Array Assignment
| From: | Mark Cain | Date: | Sat, 05 May 2001 14:55:27 +0000 |
| Subject: | Array Assignment | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-51423@lists.php.net to get a copy of this message | ||
I'm new to PHP (which will be obvious in just a minute).
In Perl I can assign dynamic keys ad infinitum to an array such as:
$sku{$id}{$line}{$price} = 99;
But the syntax is escaping me for the same function in PHP.
As I was trying to debug my thinking, I ran the following little test and am
confused about the result.
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
$first[$second] = "pass";
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
Thanks