I have this if I explain it to a partner but I do not understand it well
if (!($result = $db->sql_query($q)));
Could you explain how it is read and how it works? thanks
I have this if I explain it to a partner but I do not understand it well
if (!($result = $db->sql_query($q)));
Could you explain how it is read and how it works? thanks
!
is called the denial opeardor. This what it does is that it denies the Boolean expression according to the result of it. For example:
echo !true;
You'll notice how it prints false
, this because false
is the denial of true
.
In your case, the function $db->sql_query($q)
returns a boolean. That result is saved in $result
so $result
is now type boolean
, if the result is true
, this is denied to false
so the if
is not met and ignored your body, otherwise if you return false
, this would be denied and become true
so if you run the body of if
.
This would be the broken code to be better understood:
$result = $db->sql_query($q);
if (!$result)
{
//...
}
The if would only be executed if $ result were false, since! Deny the value false
to true
.