PHP - Adding Parameters and Returning Values to method in class

Introduction

You can add parameters to a method so that it can accept arguments to work with.

A method can return a value.

You add parameters and return values in much the same way as with functions.

To add parameters, specify the parameter names between the parentheses after the method's name:

public function aMethod($param1, $param2) {
    // (do stuff here)
}

To return a value from a method - or to simply exit a method immediately - use the return keyword:

public function aMethod($param1, $param2) {
    // (do stuff here)
    return true;
}

Related Topic