How can the principles of database normalization be applied to improve PHP code efficiency when working with arrays?

When working with arrays in PHP, applying the principles of database normalization can improve code efficiency by reducing redundancy and ensuring data is stored in a structured manner. This can lead to cleaner, more maintainable code and improved performance.

// Example of applying normalization principles to improve PHP code efficiency when working with arrays

// Original array with redundant data
$users = [
    ['id' => 1, 'name' => 'Alice', 'age' => 25, 'city' => 'New York'],
    ['id' => 2, 'name' => 'Bob', 'age' => 30, 'city' => 'Los Angeles'],
    ['id' => 3, 'name' => 'Alice', 'age' => 25, 'city' => 'Chicago'],
];

// Normalized array with separate arrays for users and cities
$users = [
    ['id' => 1, 'name' => 'Alice', 'age' => 25, 'city_id' => 1],
    ['id' => 2, 'name' => 'Bob', 'age' => 30, 'city_id' => 2],
    ['id' => 3, 'name' => 'Alice', 'age' => 25, 'city_id' => 3],
];

$cities = [
    ['id' => 1, 'name' => 'New York'],
    ['id' => 2, 'name' => 'Los Angeles'],
    ['id' => 3, 'name' => 'Chicago'],
];