On 27 February 2007 04:23, Gerry D wrote: > I have a question on how to retrieve the value that corresponds to a > key in an array. > > $fruit = array('a' => 'apple', 'b' => 'banana', 'c' => 'cranberry'); > > $key = array_search($c, $fruit); > if ( $key === FALSE ) > $n = $c; > else > { > $n = $fruit[$key]; // how to get the value??? > } > > the array_search works ok, but how do I get the value? > > all I get back is 'a' or 'b', not 'apple' or 'banana'... Please show a little more code, as it looks to me as though this should work how you think it should. Specifically: how do we know what is in $c? how do you know the array_search works? how do you know $n is only getting 'a', 'b', or 'c'? (Hint: var_dump() is your friend!) Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: m.ford@xxxxxxxxxxxxxx Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php