How does object-oriented programming in PHP contribute to cleaner and more logical code compared to procedural programming?

Object-oriented programming in PHP allows for code organization through the use of classes and objects, which helps to encapsulate data and behavior. This leads to cleaner and more logical code by promoting modularity, reusability, and easier maintenance. Additionally, OOP in PHP enables the use of inheritance, polymorphism, and abstraction, which can further enhance code clarity and structure.

class Car {
    public $make;
    public $model;

    public function __construct($make, $model) {
        $this->make = $make;
        $this->model = $model;
    }

    public function getMakeAndModel() {
        return $this->make . ' ' . $this->model;
    }
}

$myCar = new Car('Toyota', 'Corolla');
echo $myCar->getMakeAndModel(); // Output: Toyota Corolla