Array confusion.

From: Date: Thu, 22 Mar 2001 19:45:32 +0000
Subject: Array confusion.
Groups: php.general 
Request: Send a blank email to php-general+get-45173@lists.php.net to get a copy of this message
H- I'm kinda new to the PHP scene so if the below plea for help is incredibly simple ... well.. What can I say? I'm stuck. I've been on the PHP website for the last hour reading the documentation on arrays and all the functions associated with it but have yet to find a straight forward explaination on how to accomplish this code. Here's what I have: (PHP4) $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? I've seen examples on printing every element of an array. Printing every element of a 2d array, poping elements from the beginning and end of an array but not an example of getting a single element from an array. I'm sure I'm doing something backwards and might even be confused on how the array works but don't know what. If any one has any better solutions to this code please feel free to post. Thanks for any assistance anyone can provide. -Sterling

« previous php.general (#45173) next »