PHP Calculation of individual income tax steps (attached code)

Source: Internet
Author: User
This time for everyone to bring the PHP calculation of personal income tax steps in detail (with code), PHP calculation of personal income tax considerations are what, the following is the actual case, together to see.

Do not use calculator deduction to calculate personal income tax, PHP custom function to achieve personal income tax calculation. It is too simple to use calculator deduction to calculate personal income tax.

PHP and JS have the same, know how to calculate the method of personal income tax in PHP, you can also write a JS code to calculate personal income tax. The difference is that JavaScript does not have foreach() such grammatical structure, but with the changes of the Times, the modern browser JS ECMASCRIPT 5 also began to support forEach() the method.

<?php/* PHP does not use calculator deduction to calculate personal income tax * @author Wu Xian * @param float $salary tax-Included income amount * @param float $deduction Insurance, etc. the default value of the amount that should be deducted 0 * @param float $threshold The default value is 3500 * @return Float | False return value is the taxable amount parameter error when returned false */function Getpersonalincometax ($salary, $deduction =0, $threshold =3500) {if (!is_numeric ($salary) | | !is_numeric ($deduction) | |    !is_numeric ($threshold)) {return false;    } if ($salary <= $threshold) {return 0;    } $levels = Array (4500, 9000, 35000, 55000, 80000, Php_int_max);    $rates = Array (0.03, 0.1, 0.2, 0.25, 0.3, 0.35, 0.45);    $taxableIncome = $salary-$threshold-$deduction;    $tax = 0;      foreach ($levels as $k = + $level) {$previousLevel = IsSet ($levels [$k-1])? $levels [$k-1]: 0;        if ($taxableIncome <= $level) {$tax + = ($taxableIncome-$previousLevel) * $rates [$k];      Break    } $tax + = ($level-$previousLevel) * $rates [$k];    } $tax = Round ($tax, 2);  return $tax; }/* Example */echo GetpersOnalincometax (10086.11); Run result:762.22?>

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

thinkphp controller variables show steps in the template

Laravel ORM on Model::find caching method

Curl download file shows real-time progress bar (with code)

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.