I wanted to know if there is any kind of 'break' in IF
. My question is based on the example below. When the b()
function returns false
all subsequent comparisons are not performed. I thought the condition would compare all the values and return the result.
I may be talking bullshit, but it seems that it throws a break when it finds a result that does not exceed the condition, something like throw
.
$a = function(){ echo 'a'; return 1; };
$b = function(){ echo 'b'; return 1; };
$c = function(){ echo 'c'; return 1; };
if( $a() && $b() && $c() )
echo 'sucesso';
output : a b c sucesso
$a = function(){ echo 'a'; return 1; };
$b = function(){ echo 'b'; return 0; };
$c = function(){ echo 'c'; return 1; };
if( $a() && $b() && $c() )
echo 'sucesso';
output : a b
My case was to use a if
where the third condition depended on the other two as true, saving if + if
. In the above example it worked as expected, but it really was news to me.