0

I need to calculate the average daily growth of my company here in storage, but I have doubts, what would be the correct way? Sorry for using Google Translator. =)

Space Used in Storage:

f_date      f_used
12/03/2013  2708100
13/03/2013  2708663
14/03/2013  2712155
15/03/2013  2715932
16/03/2013  2717823
17/03/2013  2719575
18/03/2013  2723095
19/03/2013  2726682
20/03/2013  2730365
21/03/2013  2733563
22/03/2013  2737411
23/03/2013  2644001
24/03/2013  2645764

My code in PHP:

for ($i = 1; $i < sizeof($array); $i++) {
 $resultado[] = $array[$i] - $array[$i-1];
}
echo array_sum($resultado)/count($resultado);

My result is: -5194.6666666667, is it wrong?

Johan
  • 74,508
  • 24
  • 191
  • 319

1 Answers1

0

The algorithm is correct and is giving you the average of the daily difference.

Example:

f_date      f_used  difference
12/03/2013  2708100
13/03/2013  2708663  563
14/03/2013  2712155  3492
                     ----
                     4055
4055 / 2 (difference count) = 2027.5

See the demo

Kermit
  • 33,827
  • 13
  • 85
  • 121