It doesnt matter to him.
It doesnt matter for him.

I heard them both before from the mouths of other people. I think they essentially mean the same thing.
Hi AlexandreA

I'd say there is a difference.

It doesn't matter to him.
=> This can be used to say that "he himself has no preference about something".

It doesn't matter for him. => If someone used this wording, I would interpret it to mean "it makes no difference in his case" or "it doesn't/won't affect him".
Thank you for your help.