In the context of PHP development, how can the userLeagueImage function be modified to display icons for all teams associated with a user?

The userLeagueImage function needs to be modified to retrieve and display icons for all teams associated with a user, instead of just one team. This can be achieved by fetching all team data for the user and looping through each team to display their respective icons.

function userLeagueImage($userId) {
    // Fetch all teams associated with the user
    $teams = getTeamsByUserId($userId);

    // Loop through each team and display their icon
    foreach ($teams as $team) {
        echo '<img src="' . $team['icon'] . '" alt="' . $team['name'] . '">';
    }
}

// Example function to get teams associated with a user
function getTeamsByUserId($userId) {
    // Query database to fetch teams for the user
    // This is just a placeholder, actual implementation may vary
    $teams = [
        ['name' => 'Team A', 'icon' => 'teamA.png'],
        ['name' => 'Team B', 'icon' => 'teamB.png'],
        ['name' => 'Team C', 'icon' => 'teamC.png']
    ];

    return $teams;
}

// Call the function with the user's ID
$userID = 123;
userLeagueImage($userID);