What function can be used to remove trailing spaces from a string in PHP?

Trailing spaces in a string can be removed using the `rtrim()` function in PHP. This function removes any whitespace characters, including spaces, tabs, and newlines, from the end of a string. By applying `rtrim()` to the string, you can ensure that no trailing spaces are present, which can be useful for data validation or formatting purposes.

$string = "Hello World    ";
$trimmedString = rtrim($string);
echo $trimmedString; // Output: "Hello World"