How can the issue of line breaks at the end of an array index be resolved in PHP?

When accessing an array index in PHP, sometimes there may be unwanted line breaks at the end of the value. This can be resolved by using the trim() function to remove any whitespace characters, including line breaks, from the beginning and end of the string.

$value = trim($array[$index]);