![]() |
VOOZH | about |
Simple interest is the method to calculate the interest where we only take the principal amount each time without changing it for the interest earned in the previous cycle.
The formula to calculate Simple Interest is -
SI = P * R * T / 100Where -
In this article, we will explore how to calculate simple interest in PHP using different approaches.
If you only need to perform the conversion once or in a specific context, you can do the calculation inline without defining a separate function.
Example: Illustration of program to find Simple Interest in PHP using inline calculations.
Simple Interest: 450
Time Complexity: O(1)
Auxiliary Space: O(1)
Defining a function to calculate simple interest is a reusable and modular way to perform the calculation. The simpleInterest( ) function takes the principal, rate, and time as arguments and returns the simple interest.
Example: Illustration of program to find Simple Interest in PHP using a function.
Simple Interest: 450
Time Complexity: O(1)
Auxiliary Space: O(1)
In a more interactive scenario, you might want to calculate simple interest based on user input. This can be done using an HTML form to get the principal, rate and time as input and PHP to process the input.
Example: Illustration of program to find Simple Interest in PHP through User Input using HTML.
Output
Time Complexity: O(1)
Auxiliary Space: O(1)