What are the best practices for handling session data in PHP to avoid loss or interference when switching accounts?

When switching between user accounts in a PHP application, it is important to properly handle session data to avoid loss or interference. One common approach is to clear the session data for the current user before initializing the session for the new user. This ensures that each user's data is kept separate and prevents any potential conflicts.

// Clear current session data before switching accounts
session_unset();
session_destroy();

// Start a new session for the new user
session_start();