When the actual power consumption in the first level of the power base range, ladder tariff = basic electricity price x actual electricity consumption;
When the actual power consumption is between the second-level power base range, the ladder tariff = basic electricity price x first-level power + two-stage electricity price X (actual power consumption-the lower limit of the second power base);
When the actual power consumption exceeds the second power base limit, ladder tariff = basic electricity price x first level + second gear price x second Stage power base interval range + three price X (actual power consumption-the second level of power base limit).
The first level of power for each household 0-260 kwh per month of electricity consumption, the electricity price is not adjusted for 0.61 yuan/kwh;
The second level of electricity for each household 261-600 kilowatt-hour power consumption, the electricity price per kilowatt hour increase of 0.05 yuan, is 0.66 yuan/kwh;
The third gear power for each household 601-kilowatt hours per month and above the power consumption, the electricity price per kilowatt hour increase of 0.30 yuan, is 0.91 yuan/kwh.
Reply to discussion (solution)
$x = +, $y = 0;switch ($x) {case $x >: $y + = * $x -600) * 0.91; $x =; Case $x > 260: $y + = ($x -260) * 0.66; $x = 260; Default: $y + = $x * 0.61;} Echo $y;
Different processing is performed according to different conditions, and a switch statement is available.
This is similar to the arithmetic expressions written in elementary school, just to use PHP to write.
Function fee ($el & $fee) {switch ($el) {case $el >: $fee + = ($el -600) *0.91+fee ($fee), break;case $el > 260 : $fee + = ($el -260) *0.66+fee (260, $fee); Break;default: $fee + = $el *0.61;break;}} Fee ($fee); Echo $fee;