If $key is not a string the check might fail

Always use === to compare values :-)