How can PHP developers efficiently check if a value already exists in an array before adding it?

When adding values to an array in PHP, developers often need to check if a value already exists in the array to avoid duplicates. One efficient way to do this is by using the in_array() function, which checks if a specific value exists in an array. By using this function before adding a value to the array, developers can prevent duplicates and ensure data integrity.

$value = "new_value";
$array = ["value1", "value2", "value3"];

if (!in_array($value, $array)) {
    $array[] = $value;
}