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

Jonah Shi
Jonah Shi
10,140 Points

Why the if statement uses and instead of or

The if statement which checks the ingredient amount, if($amount != null && !is_float($amount) && !is_int($amount)), why use and instead of or? As she said later herself or....or?

andren
andren
28,558 Points

Can you post a link to the video you are referencing? Without seeing the code in its entirety it's hard to say whether && or || is the correct operator to use.

3 Answers

I don't know what's the context behind this code, but if any of those conditions returns false, the entire if statement will be skipped, even if one of them is true it won't matter

There she is doing that to check if there is a value inside $amount that is: checking whether or not you entered a value for $amount, and then checking if that value is not float value, and then checking if that value is not an int value, if any of those conditions return true, then the script shall end, so if for example you enter a string value such as: "2" for amount within quotes the script will end because $amount is not empty, and $amount is not a float, and $amount is not an int value just as she says in the video and in the code, if on the other hand there isn't a value entered into that value, let's say you don't pass in that argument, then the program shall continue, as she says $amount and $measure are optional, so they are set to NULL by default