I'm working on a project and I can't wrap my head around on a calculation that needs to be done on a multidimensional array. Quick background, it's a hotel benchmarking tool and I need to calculate the market penetration index (MPI). I have an array with 3 main arrays. First 2 are the hotels which are being compared and the last one is the MPI array.
Each array contains an array for every month the user selects. Inside THAT array is data that needs to be used for calculations. Here is an example:
Array
(
[Competitive set] => Array
(
[Sep 11] => Array
(
[0] => Array
(
[minmonth] => 2011-09-01
[maxmonth] => 2011-09-01
[nrcheck] => 13
[data] => 67.6
)
)
[Oct 11] => Array
(
[0] => Array
(
[minmonth] => 2011-10-01
[maxmonth] => 2011-10-01
[nrcheck] => 13
[data] => 63.6
)
)
[Nov 11] => Array
(
[0] => Array
(
[minmonth] => 2011-11-01
[maxmonth] => 2011-11-01
[nrcheck] => 13
[data] => 59.2
)
)
[Dec 11] => Array
(
[0] => Array
(
[minmonth] => 2011-12-01
[maxmonth] => 2011-12-01
[nrcheck] => 13
[data] => 54.6
)
)
)
[Test] => Array
(
[Sep 11] => Array
(
[0] => Array
(
[minmonth] => 2011-09-01
[maxmonth] => 2011-09-01
[nrcheck] => 89
[data] => 71.5
)
)
[Oct 11] => Array
(
[0] => Array
(
[minmonth] => 2011-10-01
[maxmonth] => 2011-10-01
[nrcheck] => 89
[data] => 67.0
)
)
[Nov 11] => Array
(
[0] => Array
(
[minmonth] => 2011-11-01
[maxmonth] => 2011-11-01
[nrcheck] => 91
[data] => 63.1
)
)
[Dec 11] => Array
(
[0] => Array
(
[minmonth] => 2011-12-01
[maxmonth] => 2011-12-01
[nrcheck] => 89
[data] => 57.5
)
)
)
[MPI] => Array
(
[Sep 11] => Array
(
[0] => Array
(
[minmonth] => 2011-09-01
[maxmonth] => 2011-09-01
[nrcheck] => 89
[data] => 71.5
)
)
[Oct 11] => Array
(
[0] => Array
(
[minmonth] => 2011-10-01
[maxmonth] => 2011-10-01
[nrcheck] => 89
[data] => 67.0
)
)
[Nov 11] => Array
(
[0] => Array
(
[minmonth] => 2011-11-01
[maxmonth] => 2011-11-01
[nrcheck] => 91
[data] => 63.1
)
)
[Dec 11] => Array
(
[0] => Array
(
[minmonth] => 2011-12-01
[maxmonth] => 2011-12-01
[nrcheck] => 89
[data] => 57.5
)
)
)
)
here is a pastebin with var_export as suggested (can't seem to format it propperly here) http://pastebin.com/b8hYM7TW Sorry for the huge code block but it had to be this big =( Either way currently the 'data' for MPI is wrong. That needs to become the data of the first array divided by the data of the second array and multiplied by 100 (percentage).
The keys "Competitive Set" and "Test" are variable and not available in the scope i'm working in so those static names can't be used.
I read about recursive functions but I'm still not getting it...