You can:
if ( in_array ( $CUST_CITY,array_keys($city_array )) ) echo " FOUND
$CUST_CITY IN ARRAY";
        else echo "Not found";
A+
Alain

-----Original Message-----
From: Asendorf, John [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 04, 2001 10:17 AM
To: Php-Windows (E-mail)
Subject: [PHP-WIN] in_array with an associative array... stuck


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 - [EMAIL PROTECTED]
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


--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to