Write a program to calculate electricity bill in PHP
In this exercise, you will learn a PHP program to calculate an electricity bill based on some conditions using if-else statements. The electricity consumption charge is easy to understand and calculate. It is measured in kWh (kilowatt hours). The rate of electricity bill varies depending on the geographic location and the amount of consumption. Suppose we have the following conditions for rates of electricity calculation -
- First 1 to 100 units – Rs. 8/unit
- Next 100 to 200 units – Rs. 12/unit
- Next 200 to 300 units – Rs. 16/unit
- above 300 units – Rs. 20/unit
The following program is the implementation of the above methodology -
Here is the sample execution of the above program.

need an explanation for this answer? contact us directly to get an explanation for this answer