How can a method within a class in PHP be displayed with a return value?

To display a method within a class in PHP with a return value, you can create an instance of the class and then call the method on that instance. The method should return a value that can be stored in a variable or directly outputted. Make sure the method is defined as public so it can be accessed from outside the class.

class MyClass {
    public function myMethod() {
        return "Hello, World!";
    }
}

$obj = new MyClass();
echo $obj->myMethod(); // Output: Hello, World!