How can using private functions improve code readability and maintainability in PHP?

Using private functions in PHP can improve code readability and maintainability by encapsulating logic that is only relevant to a specific class or method. This helps to keep the code organized and easier to understand, as developers can focus on the public interface of the class without being distracted by implementation details. Additionally, private functions can prevent other parts of the codebase from accessing and potentially modifying internal logic, reducing the risk of unintended side effects.

class MyClass {
    private function calculateTotal($price, $quantity) {
        return $price * $quantity;
    }

    public function displayTotal($price, $quantity) {
        $total = $this->calculateTotal($price, $quantity);
        echo "Total: $total";
    }
}

$myClass = new MyClass();
$myClass->displayTotal(10, 5);