The empty string ('') will compare correctly using ==, because it's a string. This issue is specifically when you are testing a numeric value against a string. Somewhere in your code $sw is getting set to the numeric value 0 and not the empty string as you thought and that's what lead to the problem.
In general, using strict comparison is a good habit to develop to save help ensure you're dealing with the correct types.