2
Example scenario
Example 1
$var = 'A';
function testar($v)
{
echo 'Início';
if ($v == 'A') {
echo ' : true';
return true;
} else {
echo ' : false';
return false;
}
echo ' : Fim';
}
testar($var);
Exit: Início : true
Example 2
$var = 'A';
function testar($v)
{
echo 'Início';
if ($v == 'A') {
echo ' : true';
} else {
echo ' : false';
}
echo ' : Fim';
}
testar($var);
Exit: Início : true : Fim
Doubt
- Why the
return
"eliminates" the rest of the script, since it is not contained inif
?
Because when you use a Return it returns the function result.
– Wictor Chaves
When you use the Return is to indicate that that is the expected result of the function, then finding this result, it will return the value of the function and end the function.
– Wictor Chaves
https://answall.com/q/115335/101 e https://answall.com/q/331155/101
– Maniero
Related => Is it recommended to use loose Return in a PHP file? When?
– rray