How to calculate depreciation per years in PHP

1 Answer

0 votes
$amount = 1000;
$deppercent = 40; // 40%
$years = 3;
          
$amount_left = $amount;
          
$annual_depreciation = 0;
         
echo "Initial amout = " . $amount_left . "\n";
          
for($i = 0; $i < $years; $i++) {
    $annual_depreciation = ($deppercent * $amount_left) / 100;
    $amount_left = $amount_left - $annual_depreciation;
    echo "Year :" . ($i + 1) . " Annual depreciation = " . $annual_depreciation . " Amount left = " . $amount_left . "\n";
}
  
echo "Amount after depreciation = " . $amount_left;
  
  
  
  
  
/*
run:
   
Initial amout = 1000
Year :1 Annual depreciation = 400 Amount left = 600
Year :2 Annual depreciation = 240 Amount left = 360
Year :3 Annual depreciation = 144 Amount left = 216
Amount after depreciation = 216
   
*/

 



answered Aug 15, 2021 by avibootz

Related questions

1 answer 208 views
1 answer 227 views
227 views asked Aug 15, 2021 by avibootz
1 answer 281 views
1 answer 319 views
1 answer 248 views
1 answer 422 views
1 answer 264 views
...