Re: Array confusion.

From: Date: Thu, 22 Mar 2001 20:22:24 +0000
Subject: Re: Array confusion.
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-45177@lists.php.net to get a copy of this message
H- Thanks to all that wrote in with input on this issue. I really appreciate the assistance. Thanks to CC Zona and James for the code sample. It looks like there were typo's in my code and it threw me for a minute after recieving/applying all the emails. That backslash wasn't suppose to be in the original email I sent out, it was just from my Emacs window wrapping and the = next to Dec became a problem after I quoted everything else but I found it eventually. Thanks again. It's now working as I expected it too. -Sterling CC Zona wrote: > > 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 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#45177) next »