Re: Array confusion.
| From: | CC Zona | Date: | Thu, 22 Mar 2001 19:53:44 +0000 |
| Subject: | Re: Array confusion. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-45174@lists.php.net to get a copy of this message | ||
In article <3ABA565C.D65183EE@omeninc.com>,
smullett@omeninc.com (Sterling) wrote:
> $m = "03";
> $list = array(01=>"Jan", 02=>"Feb", 03=>"Mar",
> 04=>"Apr", 05=>"May",
> 06=>"Jun", 07=>"Jul", 08=>"Aug",
> 09=>"Sep\", 10=>"Oct", 11=>"Nov",
> 12="Dec");
> $month = $list[$m];
> print "$month\n";
>
> What I want to print is the month in Text format, which in this instance
> should be Mar .
> I even tried: $month = array_keys($list, $m);
>
> Now I know that $list[x]; references the location of an item so I know
> why the previous code doesn't work in that respect, since nowhere is 01
> a location but an association within the array. Right?
The keys to an associative array should be quoted. Also, that escaped
quote on "Sep\" is throwing everything off. Try:
$m = "03";
$list = array("01"=>"Jan", "02"=>"Feb",
"03"=>"Mar", "04"=>"Apr",
"05"=>"May", "06"=>"Jun",
"07"=>"Jul", "08"=>"Aug",
"09"=>"Sep",
"10"=>"Oct",
"11"=>"Nov","12"="Dec");//keys quoted, no escaped quotes
$month = $list["$m"];//associative array element index quoted
print "$month\n";
--
CC