Well for one, this:
if($var = 'foo')
first assigns the value of 'foo' to the variable $var, meaning you've now lost whatever value $var previous had. '=' is the assignment operator, not a comparative operator (such as '==' or '===').
Second, can you show us how that function was called? Specifically, you haven't told us what the value of $selected was or what keys were contained in $array.