本文實例講述了PHP計算個人所得稅。分享給大家供大家參考,具體如下:
不使用速算扣除數計算個人所得稅,PHP自定義函數實現個人所得稅計算。使用速算扣除數計算個人所得稅過于簡單,略過不提。
PHP和JS有相同之處,知道PHP計算個人所得稅的方法以后,也可以同理寫出JS代碼個算個人所得稅。不同之處在于,javascript沒有foreach()
這樣的語法結構,不過隨著時代的變遷,現代瀏覽器中JS ECMASCRIPT 5也開始支持forEach()
方法了。
?php /* PHP不使用速算扣除數計算個人所得稅 * @author 吳先成 * @param float $salary 含稅收入金額 * @param float $deduction 保險等應當扣除的金額 默認值為0 * @param float $threshold 起征金額 默認值為3500 * @return float | false 返回值為應繳稅金額 參數錯誤時返回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(1500, 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; } /* 示例 */ echo getPersonalIncomeTax(10086.11); //運行結果:762.22 ?>
PS:這里再為大家推薦幾款相關的在線計算工具供大家參考:
在線個人所得稅計算器(2008版):http://tools.jb51.net/jisuanqi/tax_calc
在線個人所得稅計算工具(2011版):http://tools.jb51.net/jisuanqi/tax_jisuanqi
在線銀行按揭貸款計算器:http://tools.jb51.net/jisuanqi/anjie_calc
在線存款計算器:http://tools.jb51.net/jisuanqi/cunkuan_calc
在線投資理財計算器:http://tools.jb51.net/jisuanqi/touzilicai_calc
在線養老保險繳存/養老規劃計算器:http://tools.jb51.net/jisuanqi/yanglao_calc
更多關于PHP相關內容感興趣的讀者可查看本站專題:《PHP數學運算技巧總結》、《PHP運算與運算符用法總結》、《php字符串(string)用法總結》、《PHP數組(Array)操作技巧大全》、《PHP數據結構與算法教程》、《php程序設計算法總結》及《php正則表達式用法總結》
希望本文所述對大家PHP程序設計有所幫助。