What is the best practice for avoiding repetitive if statements when assigning values to session variables in PHP?

To avoid repetitive if statements when assigning values to session variables in PHP, you can use a switch statement instead. This allows you to handle multiple cases more efficiently and in a cleaner way. By using a switch statement, you can easily assign different values to session variables based on different conditions without having to write multiple if statements.

// Example of using a switch statement to assign values to session variables
switch ($condition) {
    case 'case1':
        $_SESSION['variable'] = 'value1';
        break;
    case 'case2':
        $_SESSION['variable'] = 'value2';
        break;
    default:
        $_SESSION['variable'] = 'default value';
}