How does OOP help in structuring code and improving efficiency in PHP projects?

Object-oriented programming (OOP) helps in structuring code by organizing related data and functions into classes and objects. This improves code readability, reusability, and maintainability. In PHP projects, OOP can also improve efficiency by promoting code modularity and encapsulation, allowing for easier debugging and testing.

class User {
    private $name;
    private $email;

    public function __construct($name, $email) {
        $this->name = $name;
        $this->email = $email;
    }

    public function getName() {
        return $this->name;
    }

    public function getEmail() {
        return $this->email;
    }
}

$user1 = new User('John Doe', 'john.doe@example.com');
echo $user1->getName(); // Output: John Doe
echo $user1->getEmail(); // Output: john.doe@example.com