Open the terminal and type:
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.3 # The latest version in this repo for 18.04 and 20.04 is currently php7.4.
The latest version in ppa:ondrej/php for 22.04 is currently php8.2 but php7.4 is also still supported.
php7.3 will be updated automatically when updates become available. Alternatively you can build php7.3 from source in Ubuntu 18.04, but it will not be updated automatically, and it also takes more than an hour to build if you want to test it too.
After installing php7.3 you can show php7.3 modules that can also be installed by running the following command:
apt-cache search php7.3 | grep php7.3
A quick one-line command to install the same packages on php7.3 as php7.2:
sudo apt install $(apt list --installed | grep php7.2- | cut -d'/' -f1 | sed -e 's/7.2/7.3/g')