Jump to content

return keyword


jimfog

Recommended Posts

Despite I know what a return keyword does am still confused regarding the practical applications of it. I reached a point in my code though that I might have to use and as such I would like to ask if my logic is correct. I have made a function that checks the existence of a cookie in a user's PC-no need to post all the code here.So the pseudo code would go like this:if(checkcookie==true){do this}else{...}Am I right to assume that the checkcookie function must a have a return keyword somewhere in it-specifically when the cookie has been checked againsta the Db-or else the above code will not work?

Link to comment
Share on other sites

yes checkcookie() have to return some value(in this case boolean true or false) which you will check against condition. if you dont return anything the value will be null.

Link to comment
Share on other sites

I think you're overthinking it. A function is a piece of code that accepts some inputs, the parameters, and usually provides some output. The return statement is how to tell the function to return the output that you want it to. Look at the manual for any function, like this one: http://www.php.net/manual/en/function.str-replace.php That function accepts up to 4 parameters as inputs, and it returns a value as output. This is the description of what it returns:

Return Values This function returns a string or an array with the replaced values.
The return statement is how functions return values. There's not much more to know about it than that. Plan your algorithms accordingly. If you want your function to return a value then yes, you need a return statement.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...