Using PHP language to edit ladder charge method

Source: Internet
Author: User
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;
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.