In what ways can PHP code be normalized and improved for better scalability and maintainability, especially when dealing with complex data structures like in the provided example?

To improve scalability and maintainability of PHP code dealing with complex data structures, one approach is to use object-oriented programming principles like encapsulation, inheritance, and polymorphism. By organizing code into classes and defining clear relationships between them, the code becomes more modular, easier to understand, and simpler to extend or modify in the future.

class User {
    private $id;
    private $name;
    
    public function __construct($id, $name) {
        $this->id = $id;
        $this->name = $name;
    }
    
    public function getId() {
        return $this->id;
    }
    
    public function getName() {
        return $this->name;
    }
}

$user1 = new User(1, 'Alice');
$user2 = new User(2, 'Bob');

echo $user1->getName(); // Output: Alice