JustinK101 Posted January 25, 2007 Share Posted January 25, 2007 I have an array filled with custom keys and values like so:Array ( [_other_unknown_sic] => Other - Unknown SIC [acoustical_contractors_174202] => Acoustical Contractors 1742-02 [aerospace_381201] => Aerospace - 3812-01 )How can I do an IF statement to look for a given key, call it myKey in the array of keys, and if a match is found return the value correspoding to the matched key.Thanks Link to comment https://forums.phpfreaks.com/topic/35709-array-lookup-table/ Share on other sites More sharing options...
zq29 Posted January 25, 2007 Share Posted January 25, 2007 [code]<?phpif(array_key_exists($my_key,$my_array)) echo $my_array[$my_key];?>[/code] Link to comment https://forums.phpfreaks.com/topic/35709-array-lookup-table/#findComment-169169 Share on other sites More sharing options...
JustinK101 Posted January 25, 2007 Author Share Posted January 25, 2007 SemiApocalyptic:Does this look right, just expanded one value into a whole lot of values from mysql.while($row = mysql_fetch_assoc($result)){ if(array_key_exists($row['sic_c'], $myArray)) { $sql = "UPDATE leads_cstm SET sic_custom_c = '" . $myArray[$row['sic_c']] . "' WHERE id = '" . $row['id'] . "' LIMIT 1"; mysql_query($sql) or die(mysql_error()); } } Link to comment https://forums.phpfreaks.com/topic/35709-array-lookup-table/#findComment-169185 Share on other sites More sharing options...
zq29 Posted January 25, 2007 Share Posted January 25, 2007 [quote author=JustinK101 link=topic=124032.msg513412#msg513412 date=1169752819]SemiApocalyptic:Does this look right[/quote]Try it; if it works, it looks right. If not, come back with the problem you're having ;) Link to comment https://forums.phpfreaks.com/topic/35709-array-lookup-table/#findComment-169200 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.