When I run the following, I get 'B.C.', but I’m trying to get 'BC'.
I set array_search to do a strict comparison, why isn’t it returning "BC"?
If I pass "Alberta", I get "AB", which is correct.
<?
function cleanProvince($province)
{
$values = array(
'AB' => 'Alberta',
'BC' => 'B.C.',
'BC' => 'British Columbia',
'ON' => 'Ontario',
'ON' => 'Onatrio',
'ON' => 'Ont',
'NS' => 'Nova Scotia',
'QC' => 'Quebec'
);
if ($key = array_search(@$province, $values, true)) {
return $key;
} else {
return $province;
}
}
echo (cleanProvince("B.C."));
?>
You cannot have multiple keys in one array. When you do that, the 2nd one overrides the first.
You’re passing
"B.C."tocleanProvince. That’s not in$values, soarray_searchreturnsfalse, thuscleanProvincereturns"B.C.".