This forum is now read-only. Please use our new forums! Go to forums
I don't understand what "if ($flip)" does
A can’t catch what condition “if ($flip)” does.
In previous lessons were only f.i. if ($flip <10) - that I can get: the variable $flip should be less then 10. Ok. But what should be $flip in if($flip) when there is nothing to be compared with?!
I’m really stuck.
And BTW, I also do not understand what do the $variavle = true / false. Compared to what the’re true or false?
Thanks in advance.
Answer 5155970c5b4d25ba970010b7
True and false can also be represented with integers where 1 is true and 0 is false. If we create a variable that is assigned an integer of either 1 or 0 (as in the case of the $flip code), PHP can evaluate the variable as either “true” or “false”.
In a loop, the code inside the curly brackets is executed depending on whether the calculation inside the parenthesis evaluates to true or false. When your code shows ($flip < 10), it compares the value of $flip against 10 and returns “true” if $flip is less than 10 or “false” if greater than or equal to 10 and then proceeds accordingly.
In the case of ($flip), the code checks to see if the value of $flip is 1 or 0 and then returns “true” or “false” accordingly. Make sense?
On a side note, when using a number variable as a boolean (true/false), ANY number other than 0 returns as TRUE.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
3 comments
great response, thank you
thanks for this response. I was stuck on this, too.
Thanks a lot for your response!