What is the role of in_array function in PHP and how can it be utilized to determine if an ID is already present in an array?

The in_array function in PHP is used to check if a specific value exists in an array. To determine if an ID is already present in an array, you can use the in_array function by passing the ID you want to check for as the first parameter and the array containing the IDs as the second parameter. The function will return true if the ID is found in the array, and false if it is not.

$ids = [1, 2, 3, 4, 5];
$id_to_check = 3;

if (in_array($id_to_check, $ids)) {
    echo "ID $id_to_check is already present in the array";
} else {
    echo "ID $id_to_check is not present in the array";
}