【发布时间】:2023-03-05 10:50:02
【问题描述】:
我正在尝试实现一种结果,在该结果中,我可以获得“每天”的不同值与“35 天”的“总值”,然后我想将值保存在列中(ROI ) 用户表:
目前我正在尝试这样实现:
$total_days = 35;
$total_amount = 200;
$arr = array();
for($i = 0; $i < $total_days; ++$i)
{
$arr[] = rand(0.0, 1000.0);
}
$actual_sum = array_sum($arr);
for($i = 0; $i < $total_days; ++$i)
{
$arr[$i] *= $total_amount /$actual_sum;
//echo $arr[$i]."<BR><BR>";
}
$sum = array_sum($arr);
//echo "Sum = ".$sum;
结果是:
*********************************************
5.2625698324022
4.9162011173184
0.27932960893855
5.9776536312849
9.7430167597765
and so on for the total 35 days
Sum = 200
**********************************************
这导致我将所有天的值放在一起,现在我需要做的是只获取一天的值,然后我将在表中插入该值,此代码将每天通过 cron 作业运行 35 天。
我的问题是如何在变量中只获取一个值,以便我可以将其保存在表中?
像这样:
$value_to_insert = 5.26 (the first generated value for first day of cron job running);
And there will be the same for 2nd day cron job ($value_to_insert should be = 4.91)
另外,如果有什么好主意,我如何管理所有天的值,所以如果 cron 将在第 35 天运行,所有插入的值应该等于 $total_amount (200)?
我的表结构是:
********************************
UserID (int)
UserName (varchar)
Email (varchar)
Earning (int)
LastROIEarning (int)
Date (timestamp)
********************************
【问题讨论】:
-
这个 cronjob 是否可以在任何时候开始,或者总是在一个月的 1 号或类似时间开始?
-
cron 作业将每天执行,即每天执行 35 天。每当 cron 作业执行时。代码将被执行。
-
所以它可以随时开始,但只能提前 35 天?
-
@bestprogrammerintheworld 没错。