What you mean with "php"?
Just a script outside of XF? Then you have to manipulate xf_user.secondary_group_ids.
You select the old value, check if the group is inside, add it or not, update, finish.
I have a lot of scripts done, but never used xf itself.
If so, it is done as an addon or done with the api.
There are some scripts with the addons from XON, i have never used or watched them, but maybe you find there an idea, how to use xf as a library from outside.
BTW: Where you have found addUserInGroup
?
Do you need something for using always or just one time? For one time, i would do it with a small script in php. (Or with a promotion?)
For a regulary use, there is an addon somewhere. And there was an addon from nobita.me; but i am not shure, if this was for xf1 or 2.