matthy matthy - 25 days ago 6
PHP Question

can php return a boolean? => return $aantal == 0;

can php return a boolean like this:

return $aantal == 0;


like in java you can

public boolean test(int i)
{
return i==0;
}


or do you Have to use a if contruction?
because if i do this.

$foutLoos = checkFoutloos($aantal);

function checkFoutloos($aantal)
{
return $aantal == 0;
}

echo "foutLoos = $foutLoos";


it echo's

foutLoos =


so not true or false

thanks
matthy

Answer

It returns a boolean, but the boolean is not converted to a string when you output it. Try this instead:

$foutLoos = checkFoutloos($aantal);

function checkFoutloos($aantal)
{
    return $aantal == 0;
}

echo "foutLoos = " . ( $foutLoos ? "true" : "false" );