as it seems, $result (in line 40) is only used in the conditon (line 41), I'd replace it by the function call.