What's the purpose for the foam rubber liner under the headliner?

The replacement is usually foam, the original used to be some fiber matting which held up for a while but wasn’t too good. How long will the foam last is what I might wonder about next.