Alex Rivera | Logout

What does RETURN TRUE do in a php function?

Asked 2010-04-14T10:57:37.670
17

I was just looking at this code and i don't understand what RETURN TRUE does or what the point of it is? Can someone please explain?

class Elephpant {

    public $colour;

    public function dance() {
        echo "elephpant dances!\n";
        return true;
    }
}

Thankyou in advance ;-)

Edit
Report

2 Answers

6

In that specific piece of code - not very much.

In general however it would be used to return a condition of a validation or code that needs to return either a positive or a negative.

For instance, one would do the following:

public function isValidEmail($email) {
    // do work to see if email is valid
    if(/* Condition making it true */)
       return true;
    else
       return false;
}
answered 2010-04-14T10:58:55.130
1

You can read more about return here: http://www.php.net/return

There are few interesting applications of return like returning value from include-d file.

answered 2010-04-14T11:41:58.487

Your Answer