PHP如何計算個人所得稅

來源:互聯網
上載者:User
本文主要和大家介紹了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?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.