Multiple projects, and multiple PHP versions, I know it is stressful, and if you are using a Mac, and installed PHP with the help of Brew it's it adds to it.

I created this simple solution for PHP version management. I call it p

Code

#!/usr/bin/python3

import os
import inquirer
from subprocess import check_output

def main():
    php_versions = (check_output("brew list | grep php", shell=True)).decode()

    questions = [
        inquirer.List(
            "php_version",
            message="Which PHP version do you want to use?",
            choices=php_versions.split("\n"),
        )
    ]

    answers = inquirer.prompt(questions)

    current_php_version_major = float(check_output("php -r 'echo PHP_MAJOR_VERSION;'", shell=True).decode())
    current_php_version_minor = float(check_output("php -r 'echo PHP_MINOR_VERSION;'", shell=True).decode())

    current_php_version = current_php_version_major + (current_php_version_minor/10)

    check_output("brew unlink php@" + str(current_php_version), shell=True)
    check_output("brew link " + answers["php_version"], shell=True)

    print("PHP version changed to " + check_output("php -r 'echo PHP_VERSION;'", shell=True).decode())

if __name__ == "__main__": main()

All you have to do is copy the code above and paste it into your .local/bin. You can name the file whatever you want but I recommend using p.

Uses

> p

[?] Which PHP version do you want to use?: php
 > php
   [email protected]