Depend if you have an exemption visa(30 days) or a tourist visa or even better a non Im. However.. if any of the latter you do not have to leave the country. Replace bangkok from my cut and paste to phuket also. Its possible.
Requirements and procedures:
https://www.mfa.go.th/en/page/non-immigrant-visa-b?menu=5e1ff6f857b01e00a84023d4
Can I change tourist visa to non-B visa in Thailand?
International Relations Office: Changing Visa Status. Foreigners who have been holding tourist visa coming to Thailand can notify to change from tourist visa to Non-Ed (for educational purposes), or Non-B (for working). They have to proceed their changing visa status in person at the Immigration Bereau in Bangkok.