What is the purpose of declaring and calling functions within methods in PHP?

Declaring and calling functions within methods in PHP allows for better organization and reusability of code. By breaking down complex tasks into smaller, more manageable functions, you can improve the readability and maintainability of your code. Additionally, calling functions within methods can help streamline your code and make it more efficient.

class Calculator {
    public function add($num1, $num2) {
        return $this->sum($num1, $num2);
    }

    private function sum($a, $b) {
        return $a + $b;
    }
}

$calculator = new Calculator();
echo $calculator->add(5, 3); // Output: 8