How can the code be optimized to avoid unnecessary nested loops and improve efficiency?

The code can be optimized by avoiding unnecessary nested loops, which can improve efficiency by reducing the number of iterations and operations performed. One way to achieve this is by restructuring the code to use associative arrays or other data structures to store and access the necessary values without the need for nested loops.

// Original code with unnecessary nested loops
$users = [
    ['name' => 'Alice', 'age' => 30],
    ['name' => 'Bob', 'age' => 25],
    ['name' => 'Charlie', 'age' => 35],
];

foreach ($users as $user) {
    foreach ($user as $key => $value) {
        echo "$key: $value\n";
    }
}

// Optimized code using associative arrays
$users = [
    ['name' => 'Alice', 'age' => 30],
    ['name' => 'Bob', 'age' => 25],
    ['name' => 'Charlie', 'age' => 35],
];

foreach ($users as $user) {
    echo "name: {$user['name']}, age: {$user['age']}\n";
}