hi just a quick question here.
for php functions is it compulsory to return back a value ?
thanks
hi just a quick question here.
for php functions is it compulsory to return back a value ?
thanks
It depends on what you mean by that. You do not need to return something, but functions work based on the "return" command. Only one return per function, and processing of that function stops without it. If there is no return, the entire function will process every time.
Also:
So in that sense you can either pick a return value or have it automatically chosen for you: you cannot have the function skip the return, though it will literally return "nothing".Originally Posted by php.net
NULL will be equivalent to "" and FALSE if using just double equals:
if (myfunc()==FALSE) { //either it returned false or null, or 0, "", etc }
Triple equals will reveal the difference between the types:
if (myfunc()===FALSE) { //it returned specifically FALSE }
if (myfunc()===NULL) { //it "didn't" return anything, or NULL was specified }
(=='s opposite is !=, and ==='s opposite is !==)
This may be confusing, but it's worth knowing so you can respond accordingly to function returns even when there "isn't" one.
But as Nile said, no, you do not need to specify a return value.
But do remember that many functions (and most "typical" functions) are based around the idea of a return value: it's the basis of recursion, for example.
Though it's done very often, using a function without a return is not really the official use for functions.
function something() { echo 'something'; } is syntactically correct, but a little strange logically (though many/most programmers use this type at least once in a while).
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Bookmarks