How can using arrays as class variables in PHP improve code efficiency and readability?

Using arrays as class variables in PHP can improve code efficiency and readability by allowing you to store multiple related values in a single variable. This can reduce the number of individual variables needed in a class, making the code more organized and easier to maintain. Additionally, arrays provide a convenient way to iterate over and manipulate sets of data within the class.

class User {
    private $userData = [];

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

    public function getName() {
        return $this->userData['name'];
    }

    public function getEmail() {
        return $this->userData['email'];
    }
}