How can working with classes in PHP help in organizing and structuring code?

Working with classes in PHP can help in organizing and structuring code by encapsulating related data and functions into a single unit. This promotes code reusability, modularity, and maintainability. Classes also allow for better organization of code by grouping related functionality together, making it easier to manage and understand.

class User {
    private $username;
    private $email;

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

    public function getUsername() {
        return $this->username;
    }

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

    public function setUsername($username) {
        $this->username = $username;
    }

    public function setEmail($email) {
        $this->email = $email;
    }
}

$user = new User("john_doe", "john@example.com");
echo $user->getUsername();
echo $user->getEmail();