What is the purpose of creating a class with various properties and methods in PHP?

Creating a class with various properties and methods in PHP allows for better organization and encapsulation of code. It helps in creating reusable code that can be easily maintained and extended. Classes provide a way to group related functionality together, making the code more structured and easier to understand.

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;
    }

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

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

$user1->setEmail('johndoe@example.com');
echo $user1->getEmail(); // Output: johndoe@example.com