in_array with an associative array... stuck

From: Date: Tue, 04 Dec 2001 18:16:49 +0000
Subject: in_array with an associative array... stuck
Groups: php.windows 
Request: Send a blank email to php-windows+get-10727@lists.php.net to get a copy of this message
I'm attempting to see if a variable exists in an associative array but I've come up empty after two hours... any help out there? I've already tried array_search and the psuedo functions inside_array and array_in_array from the user comments in the documentation but they all return false for what is an obvious match... I've also tried this with $CUST_CITY in "'s and out of them (e.g. in_array ( "$CUST_CITY", $city_array ) and in_array ( $CUST_CITY, $city_array ) ) but I don't think I should need "'s around $CUST_CITY Pieces of the code that are relevent: $city_array = array ( 'ALEXANDRIA' => '43001' ,'GLENFORD' => '43739' ,'GRANVILLE' => '43023' ); $CUST_CITY = "GRANVILLE"; //this is actually retrieved from a database in the real code... if ( in_array ( $CUST_CITY , $city_array ) ) { if ( $debug ) { echo "<!-- FOUND $CUST_CITY IN ARRAY -->\n"; } echo "<option value=\"NOT LISTED\">NOT LISTED</option>\n"; //sift through city array and write city options foreach ( $city_array as $key => $value) { echo "<option "; if ( $CUST_CITY == $key) { echo "SELECTED"; } echo "value=\"$key\">$key</option>\n"; } echo "&nbsp;&nbsp;<input type=\"text\" name=\"ALT_CITY\" value=\"$CUST_CITY\">"; } else { if ( $debug ) { echo "<!-- DID NOT FIND $CUST_CITY IN ARRAY 5-->\n"; } echo "<option SELECTED value=\"NOT LISTED\">NOT LISTED</option>\n"; //sift through city array and write city options foreach ( $city_array as $key => $value) { echo "<option value=\"$key\">$key</option>\n"; } echo "&nbsp;&nbsp;<input type=\"text\" name=\"ALT_CITY\" value=\"$CUST_CITY\">"; } Thanks in advance. John --------------------- John Asendorf - jasendorf@lcounty.com Web Applications Developer http://www.lcounty.com - NEW FEATURES ADDED DAILY! Licking County, Ohio, USA 740-349-3631 Nullum magnum ingenium sine mixtura dementiae fuit

« previous php.windows (#10727) next »