It's absolutely necessary for criteria_greater_than
to return the value you want to return. Eg. for a function to return the value 5:
function get_5() {
return 5;
}
You use it like $var = get_5();
, but if you were setting it to a constant you would just do $var = 5;
or call_my_function(5)
. Notice you need to use return
in order to return anything in a function. Now consider this function:
function get_fx($x)
{
return function () use ($x)
{
return $x;
};
}
$v5 = get_fx(5);
$v6 = get_fx(6);
What are $v5
and $v6
?.. Well they are functions, because thats what they returned. In fact $v5() == get_5()
is true, but $6() == get_5() is false, because get_fx
return different functions (closures) dependent on the arguments passed.
If you were to skip the first return
you wouldn't get anything from the first function.. eg. $v5 and $v6 wouldn't have anything assigned. If you skipped the second return
in the returned function they wouldn't return anything when called, ie. $v5()
wouldn't return 5 and $v6()
wouldn't return 6.