ala888 Posted August 1, 2014 Share Posted August 1, 2014 In php, I often see code such as if($X = mysqli_query($CON,$SQL){//some code}does the assignment of $X actually return a true value or something? Link to comment Share on other sites More sharing options...
niche Posted August 1, 2014 Share Posted August 1, 2014 Ifs have to be true to be triggered. Link to comment Share on other sites More sharing options...
thescientist Posted August 1, 2014 Share Posted August 1, 2014 conditional statements evaluate expressions. so if that expression evaluates to true, then the if condition will be met. it's optional to assign the return value of the function to $x in this case, unless you actually plan to use it later Link to comment Share on other sites More sharing options...
justsomeguy Posted August 1, 2014 Share Posted August 1, 2014 When you evaluate an assignment expression, it evaluates the part on the left, the variable that got the assignment. So the value of ($x = func()) is the same as the value of $x. This page lists the values that will evaluate to false, everything else will evaluate to true:http://php.net/manual/en/language.types.boolean.php Link to comment Share on other sites More sharing options...
ala888 Posted August 2, 2014 Author Share Posted August 2, 2014 everything else will evaluate to true: thanks, that made it alot more clear! I thought it explicitly had to be the keyword 'true' Link to comment Share on other sites More sharing options...
justsomeguy Posted August 4, 2014 Share Posted August 4, 2014 I thought it explicitly had to be the keyword 'true'That would make 3 states: true, false, and "maybe". Computers don't have a maybe, everything is either true or false. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now