I know that != is “not equal”, but what does it mean when you have this:
if(!$something)
My first guess is something to do with exceptions, but a look around google did not return anything.
So what does this do?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Whatever is in the variable is converted to a Boolean (the variable itself of course remains intact), and then a NOT operation (
!) is done on the resulting Boolean. The conversion will happen because!is a Logical Operator and only works on Boolean values.Tip: If the variable is not expected to be Boolean, you might want to use something more specific like
isset($variable),empty($variable),$variable === '', etc. depending on what you want to check for. Check the manual for details.