'a value to become zero through loop in php
i am working on project to calculate depreciation till the values goes 1 or 0 but not go in negative. for eg: product value = 15 and rate of depreciation is 2 the result will come in this format.
| year2021| year 2022| year 2023 | year2024| year2025|year2026| year2027|
|------- |------ | ------ |------- |------ | ------ |------- |
|15-2=13 |13-2=11 | 11-2=9 |9-2=7 |7-2=5 | 5-2=3 | 3-2=1 |
$value = 15;
$dep_value=2;
$end=1;
for($i=$value-$dep_value; $i>=$end; $i--){
if($i!=1) {
echo "$i-";
} else {
echo "$i";
}
}
$year=2021;
$endyear=2026;
for($i=$year; $i<=$endyear; $i++){
if($i!=1) {
echo "$i+";
} else {
echo "$i";
}
}
my project is in php but i didn't get desired result.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
