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)