I need to know if a function in PHP is required to return a value or not.
I want to make a funtion that will return a string if it is called as an expression like this :
$str = myfunction(); //$str will contains a string
But if it is called with no requirement to return values, it will print the output to STDOUT (browser)
myfunctions(); //the result is sent to browser
How to code the checking portion in myfunction?
function myfunction() {
if (?????????)
print "hello";
else
return "hello";
}
In perl, I could do that with "wantarray" function.