How can you add two numbers in PHP?
That depends on how big your two numbers are. If you have numbers in the normal integer/double range, it is sufficient to use the “+” operator. You use it as follows:
If the numbers get bigger, you will have to use the “BC Math” or “GMP” library. Here is the example from gmp_add – Manual:
To increase the reusability of your code, it is best to encapsulate the addition in a function:
However, an object-oriented implementation would be better than Singleton: