Find Simple Interest using a Function

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.

PHP




<?php
  
// Function to calculate SI
function simpleInterest($principal, $rate, $time) {
    $interest = ($principal * $rate * $time) / 100;
    return $interest;
}
  
$principal = 1000;
$rate = 9;
$time = 5;
  
$interest = simpleInterest($principal, $rate, $time);
  
echo "Simple Interest: $interest";
  
?>


Output

Simple Interest: 450

Time Complexity: O(1)

Auxiliary Space: O(1)

PHP Program to Find Simple Interest

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 / 100

Where –

  • I is the interest.
  • P is the principal amount.
  • R is the rate of interest per annum.
  • T is the time in years.

In this article, we will explore how to calculate simple interest in PHP using different approaches.

Table of Content

  • Using Inline Calculation
  • Using a Function
  • Through User Input using HTML

Similar Reads

Find Simple Interest using Inline Calculation

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....

Find Simple Interest using a Function

...

Find Simple Interest Through User Input using HTML

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....

Contact Us