Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Arrays and Control Structures PHP Conditionals School's Out

Heriberto Nieves
Heriberto Nieves
856 Points

what does the ! means if its before a variable?

i don't know what the ! represent before the variable, does it check somethings?

example: if ( !$variable1 || !$variable2 ) { echo 'text goes here'; }

im guessing it checks if the variable is empty? thanks

2 Answers

Steven Parker
Steven Parker
229,708 Points

That's the logical "not" operator. It means "the opposite of". So if the variable contains "false", then putting "!" in front will make the result "true".

Andres Vidoza
Andres Vidoza
9,805 Points

This actually checks that the string is empty?

Steven Parker
Steven Parker
229,708 Points

The "not" operator just inverts the value. An empty string by itself is considered to be "falsey", and one with content is considered "truthy".