What are the advantages of using object-oriented programming (OOP) instead of procedural programming in PHP?

When using object-oriented programming (OOP) instead of procedural programming in PHP, you can achieve better code organization, reusability, and maintainability. OOP allows you to create classes and objects, which encapsulate data and behavior, making it easier to manage and modify your code in the long run.

// Example of using OOP in PHP
class Car {
    private $color;
    
    public function __construct($color) {
        $this->color = $color;
    }
    
    public function getColor() {
        return $this->color;
    }
}

$myCar = new Car('red');
echo $myCar->getColor(); // Output: red