Jump to content

Looping multiple arrays to perform spreadsheet like calculations


Eamonn

Recommended Posts

Hi

 

Im trying to recreate the behavior of an excel spreadsheet using php (its a long story dont ask!). Below are examples of the variables in use

 

#############################################################################################

 

$voda_mo_old['55555'] is part of an associative array like this: $voda_mo_old = array(55555 => 123, 55556 => 456, 55557 => 789);

 

$voda_mo_new['55555'] has the same keys but the values are different e.g $voda_mo_new = array(55555 => 111, 55556 => 333, 55557 => 888 );

 

$voda_rate['55555'] again has the same keys but different values: $voda_rate = array(55555 => .57, 55556 => .64, 55557 => .21);

 

$days_current_month = 16;

$days_past_month = 30;

 

####################################################################################################

 

Now I want to perform the following math operations on each key/value pair in $voda_mo_old[]

 

Below is using 55555 as an example:

 

$voda_mo_estimate['55555'] = ($voda_mo_old['55555'] / $days_past_month) * $days_current_month;

 

$voda_mo_variance['55555'] = $voda_mo_new['55555'] - $voda_mo_estimate['53501'];

 

$voda_mo_turnover_old['55555'] = $voda_mo_estimate['55555'] * $voda_rate['53501'];

 

$voda_mo_turnover_new['55555'] = $voda_mo_new['55555'] * $voda_rate['55555'];

 

$voda_mo_turnover_difference['55555'] = $voda_mo_turnover_new['55555'] - $voda_mo_turnover_old['55555'];

 

Im still very new to php and could write this out by hand for each different key/value pair but there must be a quicker way by using a loop?? I would be extremely grateful for any help anyone can provide.

 

Many thanks

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.