Php 如何从同一变量中的上一个值中减去?
问题 我面临的问题是无法从预期体重中动态减去损失。我希望在比赛日期计数结束前更改预期重量。请参考预期输出。提前谢谢 代码:Php 如何从同一变量中的上一个值中减去?,php,Php,问题 我面临的问题是无法从预期体重中动态减去损失。我希望在比赛日期计数结束前更改预期重量。请参考预期输出。提前谢谢 代码: echo "<pre>"; $benchmark = 96.5; //The first weight from which a person commits to lose their weight every week. $lose = 10; //Percentage of how much they commit to l
echo "<pre>";
$benchmark = 96.5; //The first weight from which a person commits to lose their weight every week.
$lose = 10; //Percentage of how much they commit to lose
$lose_weight = ($benchmark/100)*$lose; //This gives how much they should lose every week to meet the target
while($row_teams = mysql_fetch_assoc($result_select_teams)){
echo" {<br />";
echo" benchmark ==> ".$benchmark." Kg<br />";
echo" loss% ==> ".$lose."%<br />";
echo" lose_weight ==> ".$lose_weight." Kg<br /><br />";
echo" my_teams ==> ".$row_teams['t_name']."<br /><br />";
$playing_dates = $row_teams['playing_dates'];
$playing_dates = explode('|', $playing_dates);
$date = date('Y');
$noofweighins = count($playing_dates);
echo" noofweighins ==> ".$noofweighins."<br /><br />";
$lose_atleast = round($lose_weight/$noofweighins, 2);
$expected_weight = 0;
for($k=0; $k<count($playing_dates);$k++){
$expected_weight = $benchmark - $lose_atleast;
if(substr($playing_dates[$k], -4)<=$date){
echo" my_playing_dates ==> ".$playing_dates[$k]." to lose ==> ".$lose_atleast."<br />";
echo" Expected weight ==> ".$expected_weight."<br /><br />";
}
}
echo" }<br />";
}
}
echo "</pre>";
预期产出
benchmark ==> 96.5 Kg
loss% ==> 10%
lose_weight ==> 9.65 Kg
noofweighins ==> 10
my_playing_dates ==> 16/02/2013 to lose ==> 0.965
Expected weight ==> 95.535 (96.5 - 0.965)
my_playing_dates ==> 18/02/2013 to lose ==> 0.965
Expected weight ==> 94.57 (95.535 - 0.965)
my_playing_dates ==> 13/03/2013 to lose ==> 0.965
Expected weight ==> 93.605 (94.57 - 0.965)
my_playing_dates ==> 20/03/2013 to lose ==> 0.965
Expected weight ==> 92.64 (93.605 - 0.965)
my_playing_dates ==> 27/03/2013 to lose ==> 0.965
Expected weight ==> 91.675 (92.64 - 0.965)
my_playing_dates ==> 03/04/2013 to lose ==> 0.965
Expected weight ==> 90.71 (91.675 - 0.965)
my_playing_dates ==> 10/04/2013 to lose ==> 0.965
Expected weight ==> 89.745 (90.71 - 0.965)
my_playing_dates ==> 17/04/2013 to lose ==> 0.965
Expected weight ==> 88.78 (89.745 - 0.965)
my_playing_dates ==> 24/04/2013 to lose ==> 0.965
Expected weight ==> 87.815 (88.78 - 0.965)
my_playing_dates ==> 01/05/2013 to lose ==> 0.965
Expected weight ==> 86.85 (87.815 - 0.965)
我真的不懂PHP或其他任何东西,我只是浏览了一下你的代码,但是如果你改变
$expected\u weight=$benchmark-$lose\u至少会发生什么代码>至<代码>$expected\u weight=$expected\u weight-$lose\u至少代码>我不太懂PHP或其他任何东西,我只是浏览一下你的代码,但是如果你改变$expected\u weight=$benchmark-$lose\u至少会发生什么代码>至<代码>$expected\u weight=$expected\u weight-$lose\u至少代码>期望的结果是:
预期重量==>87.815(88.78-0.965)
当
$benchmark=96.5代码>始终保持不变
公式是:
$expected\u weight=$benchmark-$lose\u至少代码>
似乎必须在循环中更改$benchmark
,才能获得所需的结果。所需的结果是:
预期重量==>87.815(88.78-0.965)
当
$benchmark=96.5代码>始终保持不变
公式是:
$expected\u weight=$benchmark-$lose\u至少代码>
似乎您必须在循环中更改$benchmark
,以获得所需的结果。我希望显示每个播放日期的预期权重,因此所需的结果不是预期权重==>87.815(88.78-0.965)。预期输出中提到了期望的结果。您刚刚编写了87.815(88.78-0.965)
。因此,87.815=88.78-0.965
必须至少与$expected\u weight=$benchmark-$lose\u匹配
在所需结果中,您从不同的内容中减去,而不仅仅是96.5
。但是您的$benchmark
保持不变。我想显示每个播放日期的预期权重,因此期望结果不是预期权重==>87.815(88.78-0.965)。预期输出中提到了期望的结果。您刚刚编写了87.815(88.78-0.965)
。因此,87.815=88.78-0.965
必须至少与$expected\u weight=$benchmark-$lose\u匹配
在所需结果中,您从不同的内容中减去,而不仅仅是96.5
。但是您的$benchmark
保持不变。嘿,kells,稍作改动就行了!!非常感谢没问题,很高兴我能帮忙。请你+1这篇文章,我正在努力建立一些代表:)嘿,凯尔斯,稍作改动就行了!!非常感谢没问题,很高兴我能帮忙。请你+1这篇文章,我正在努力建立一些代表:)
benchmark ==> 96.5 Kg
loss% ==> 10%
lose_weight ==> 9.65 Kg
noofweighins ==> 10
my_playing_dates ==> 16/02/2013 to lose ==> 0.965
Expected weight ==> 95.535 (96.5 - 0.965)
my_playing_dates ==> 18/02/2013 to lose ==> 0.965
Expected weight ==> 94.57 (95.535 - 0.965)
my_playing_dates ==> 13/03/2013 to lose ==> 0.965
Expected weight ==> 93.605 (94.57 - 0.965)
my_playing_dates ==> 20/03/2013 to lose ==> 0.965
Expected weight ==> 92.64 (93.605 - 0.965)
my_playing_dates ==> 27/03/2013 to lose ==> 0.965
Expected weight ==> 91.675 (92.64 - 0.965)
my_playing_dates ==> 03/04/2013 to lose ==> 0.965
Expected weight ==> 90.71 (91.675 - 0.965)
my_playing_dates ==> 10/04/2013 to lose ==> 0.965
Expected weight ==> 89.745 (90.71 - 0.965)
my_playing_dates ==> 17/04/2013 to lose ==> 0.965
Expected weight ==> 88.78 (89.745 - 0.965)
my_playing_dates ==> 24/04/2013 to lose ==> 0.965
Expected weight ==> 87.815 (88.78 - 0.965)
my_playing_dates ==> 01/05/2013 to lose ==> 0.965
Expected weight ==> 86.85 (87.815 - 0.965)