PHP Version
4.0.1+
/* Removing duplicate values across arrays */
$array1 = ['apple', 'banana', 'orange']; // The array used as the comparison base
$array2 = ['banana', 'apple', 'grape'];

$result = array_diff($array1, $array2);
print_r($result);
// Array ( [2] => orange )
// The keys in the returned array are preserved from the original comparison array

/* Checking differences between arrays */
$currentUserInfo = ['id' => 1, 'name' => 'John', 'age' => 30];
$updatedUserInfo = ['id' => 1, 'name' => 'John', 'age' => 31];

$differences = array_diff($updatedUserInfo, $currentUserInfo);

if (!empty($differences)) {
    echo 'There are changes in the data. Updated fields: ';

    foreach ($differences as $key => $value) {
        echo "$key: $value ";
    }
} else {
    echo 'No changes were found.';
}
// Output: There are changes in the data. Updated fields: age: 31

/* Removing specific values from an array */
$originalArray = ['apple', 'banana', 'orange'];

$result = array_diff($originalArray, ['banana']);
print_r($result);
// Array ( [0] => apple [2] => orange )
array_diff(array $array_1, $array_2, $array_3, ...): array
$array1 = ['apple', 'banana', 'orange'];
$array2 = ['banana', 'apple', 'orange'];

$result = array_diff($array1, $array2);
print_r($result); // Array ( )
$array1 = [1, 2, 3, 3, 4, 5, 5];

$unique = array_diff($array1);
print_r($unique);
/* Output:
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 3
    [4] => 4
    [5] => 5
    [6] => 5
)
*/
$array = [1, 2, 3, 3, 4, 5, 5];

$unique = array_unique($array);
print_r($unique);
/* Output:
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
)
*/
$array1 = ['a' => 1, 'b' => 2, 'c' => 3];
$array2 = ['x' => 1, 'y' => 2, 'z' => 3];

$result = array_diff($array1, $array2);
print_r($result); // Output: Array ( )
$array1 = [1, 2, '3'];  // '3' is stored as a string
$array2 = [1, 2, 3];    // 3 is stored as an integer

$differences = array_diff($array1, $array2);

print_r($differences); // Output: Array ( )
$user_permissions = ['read', 'write', 'delete'];
$required_permissions = ['read', 'execute'];
$missing_permissions = array_diff($required_permissions, $user_permissions);

if (empty($missing_permissions)) {
    echo 'The user has all required permissions.';
} else {
    echo 'The user is missing the following permissions: ' . implode(', ', $missing_permissions);
}

// Output: 'The user is missing the following permissions: execute'
$all_options = ['apple', 'banana', 'cherry', 'date'];
$selected_options = ['banana', 'date'];
$remaining_options = array_diff($all_options, $selected_options);

echo 'Unselected options: ' . implode(', ', $remaining_options);
// Output: 'Unselected options: apple, cherry'
$raw_data = ['apple', 'banana', '', 'date', null, 'cherry'];
$cleaned_data = array_diff($raw_data, ['', null]);

print_r($cleaned_data);
/* Output:
Array
(
    [0] => apple
    [1] => banana
    [3] => date
    [5] => cherry
)
*/
$committed_files = ['file1.php', 'file2.php', 'file3.php'];
$modified_files = ['file2.php', 'file3.php', 'file4.php'];
$new_files = array_diff($modified_files, $committed_files);

echo 'New files: ' . implode(', ', $new_files);
// Output: 'New files: file4.php'