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

Scott Murray
Scott Murray
8,353 Points

Doesn't make sense...

Since you set $a = 0 which is the same as $a = false, wouldn't !$a be the same as saying $a is NOT false thus equally true???

andren
andren
28,558 Points

You don't link to the video or code you are discussing so I don't know the context of your question. But the ! operator simply reverses booleans. So true is treated as false and vice versa.

So if $a contains 0 (which is essentially false as you stated) then the ! would invert it so that it is considered to be true.

If you link to the video or code in question then I might be able to give a better explanation of what is confusing you.

1 Answer

Scott Murray
Scott Murray
8,353 Points

I understand and thank you for responding. I honestly feel like the beginning PHP course is purposely full of trick questions to trip you up and I'm finding it to be quite annoying. Here's the link to the video: https://teamtreehouse.com/library/negation-operator

Scott Murray
Scott Murray
8,353 Points

Like, on this quiz:

What will be displayed in a browser when the following PHP code is executed:

<?php $a = "Alena"; if ($a = "Treehouse") { echo "Hello Alena, "; } echo "Welcome to Treehouse!"; ?>

TIP: Check the OPERATORS

I find this to be a trick question.