2
I’m trying to set up a foreach or something similar to make the following happen:
I hold a value where the same is a fraction of 1
, in case it would be 0.00000100
that is, eight houses after the point. I also have a date, for example yesterday’s date 23/04/2015 12:30:12
.
What I’d like to do is multiply the fraction (ex: 0.00000150 * 3 = 0.00000450)
and at the date add 100
hours.
An example of how it would look, being the base value in 0.00000100 - dia 23/04/2015 14:38:45
, where it will be multiplied by 3, something like:
$multiplicado = 3;
$string = '0.00000100 - dia 24/04/2015 12:24:45';
Where the result would be a list more or less like this:
0.00000200 - dia 28/04/2015 16:24:45
0.00000300 - dia 02/05/2015 20:24:48
0.00000400 - dia 07/05/2015 00:25:14
It would be a list more or less like this, where it takes the value and multiplies the fraction by the same and sum 100
hours. It’s take what I got today 0.00000100
and show what I’ll have from here 100
hours, 200
hours and 300
hours. Of course I put multiplied by 3
, but it can be more or it can be less.
I do not know if a foreach would be ideal, but I believe that yes... I’m just not able to do it.
If anyone has any idea how to put this together, I’d appreciate it. Thank you
Multiplying fractions is not a good idea Leander. Decimal numbers are treated as floats and are not exact representations. Prefer to use an integer value, and convert to seconds, for example.
– gmsantos
Okay, multiply a given fraction by 3, and add 100 hours to a date. However you missed to clarify the most important, this operation must be executed until when? X times? Until another given date? This is the most important part to determine how the loop will be.
– user59482