There are multiple fancy scripts out there for managing PHP versions, but here I will show you how you can get the same result with just Homebrew, which you probably already have installed.
Install different PHP versions:
brew install email@example.com brew install firstname.lastname@example.org brew install email@example.com brew install firstname.lastname@example.org
Let’s say you want version
8.0, simply run:
brew unlink php && brew link email@example.com
PHP 8.0.2 (cli) (built: Feb 4 2021 17:58:53) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.2, Copyright (c) Zend Technologies with Zend OPcache v8.0.2, Copyright (c), by Zend Technologies
Simply repeat the unlink/link command every time you want to switch version.
These commands have been tested on OSX Catalina but should also work for earlier versions of OSX.