This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Evgeniy
almost 11 years

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

18 votes

Permalink

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.

points
Submitted by Eric Smith
almost 11 years

3 comments

Turancan Salur almost 11 years

great response, thank you

Uchenna Okoye almost 11 years

thanks for this response. I was stuck on this, too.

Igor Vilinchuk about 10 years

Thanks a lot for your response!