PHP string comparison, === or strcmp not working -
i have hash map contains keys sorted versions of values. example,
$hash = array( "abc" => "cab", "aas" => "sas" );
i have array of sorted strings($sorted_words) , want compare these strings keys of above hash map , if match found, store corresponding value in string. use === , strcmp(), neither works. says strings didn't match. here code :
foreach($sorted_words $sc) { foreach($hash $key => $value) { if(strcmp($sc, $key) == 0) { // or if($sc === $key) $string_match .= $value; // store corresponding value matched key. } } }
but comparison fails strcmp() returns greater 1 , '===' never returns true. can tell what's wrong ? i'm pretty sure there strings match.
try :
$string_match = ""; foreach($sorted_words $sc) { if(array_key_exists($sc, $hash)){ $string_match .= $hash[$sc]; } }
Comments
Post a Comment