How can the in_array() function in PHP be used to simplify the process of checking for duplicate entries in a session array?

When working with a session array in PHP, it can be useful to check for duplicate entries to prevent data redundancy or errors. The in_array() function can simplify this process by quickly checking if a value already exists in the array. By using in_array() in conjunction with an if statement, you can easily identify and handle duplicate entries within the session array.

// Check for duplicate entries in a session array
if(in_array($value_to_check, $_SESSION['my_array'])) {
    // Handle duplicate entry
    echo "Duplicate entry found!";
} else {
    // Add new value to session array
    $_SESSION['my_array'][] = $value_to_check;
}