Jump to content

if and &&


vincent30000

Recommended Posts

hi guys,

 

I am kind of new to php and also to programing. I would like to get your inputs on the following conditional statement.

 

if (is_array($_POST) && count($_POST) > 1)

 

now the first condition in this statement gives a true...

that is understandable but the second condition gives the result of the number of array elements passed to the post via the form. In this case its 2. Then how is this if statement is always true. I mean if we take it some thing like this

if (true && 2 >1)

hows this statement evaluated ?

 

 

I would really appreciate if some one can explain the same....

 

Thanks in advacne......

Link to comment
https://forums.phpfreaks.com/topic/198024-if-and/
Share on other sites

if (true && 2 >1)

The (bool) value of each operand, that is, the value of each expression (left and right-hand) when cast as boolean, evaluate to true, so the full "&&" statement evaluates to true.

Link to comment
https://forums.phpfreaks.com/topic/198024-if-and/#findComment-1039074
Share on other sites

thanks  tmallen.... I was trying to figure that out and realized that the > operator will be evaluated first according to the precedence rules, and then the && operator will get evaluated.... and since 2>1 is true so...the two conditions come out to be true and hence the result...

 

thanks once again...

Link to comment
https://forums.phpfreaks.com/topic/198024-if-and/#findComment-1039080
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.