Note that there are some explanatory texts on larger screens.

plurals
  1. POCalculations on multidimensional array
    primarykey
    data
    text
    <p>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.</p> <p>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:</p> <pre><code>Array ( [Competitive set] =&gt; Array ( [Sep 11] =&gt; Array ( [0] =&gt; Array ( [minmonth] =&gt; 2011-09-01 [maxmonth] =&gt; 2011-09-01 [nrcheck] =&gt; 13 [data] =&gt; 67.6 ) ) [Oct 11] =&gt; Array ( [0] =&gt; Array ( [minmonth] =&gt; 2011-10-01 [maxmonth] =&gt; 2011-10-01 [nrcheck] =&gt; 13 [data] =&gt; 63.6 ) ) [Nov 11] =&gt; Array ( [0] =&gt; Array ( [minmonth] =&gt; 2011-11-01 [maxmonth] =&gt; 2011-11-01 [nrcheck] =&gt; 13 [data] =&gt; 59.2 ) ) [Dec 11] =&gt; Array ( [0] =&gt; Array ( [minmonth] =&gt; 2011-12-01 [maxmonth] =&gt; 2011-12-01 [nrcheck] =&gt; 13 [data] =&gt; 54.6 ) ) ) [Test] =&gt; Array ( [Sep 11] =&gt; Array ( [0] =&gt; Array ( [minmonth] =&gt; 2011-09-01 [maxmonth] =&gt; 2011-09-01 [nrcheck] =&gt; 89 [data] =&gt; 71.5 ) ) [Oct 11] =&gt; Array ( [0] =&gt; Array ( [minmonth] =&gt; 2011-10-01 [maxmonth] =&gt; 2011-10-01 [nrcheck] =&gt; 89 [data] =&gt; 67.0 ) ) [Nov 11] =&gt; Array ( [0] =&gt; Array ( [minmonth] =&gt; 2011-11-01 [maxmonth] =&gt; 2011-11-01 [nrcheck] =&gt; 91 [data] =&gt; 63.1 ) ) [Dec 11] =&gt; Array ( [0] =&gt; Array ( [minmonth] =&gt; 2011-12-01 [maxmonth] =&gt; 2011-12-01 [nrcheck] =&gt; 89 [data] =&gt; 57.5 ) ) ) [MPI] =&gt; Array ( [Sep 11] =&gt; Array ( [0] =&gt; Array ( [minmonth] =&gt; 2011-09-01 [maxmonth] =&gt; 2011-09-01 [nrcheck] =&gt; 89 [data] =&gt; 71.5 ) ) [Oct 11] =&gt; Array ( [0] =&gt; Array ( [minmonth] =&gt; 2011-10-01 [maxmonth] =&gt; 2011-10-01 [nrcheck] =&gt; 89 [data] =&gt; 67.0 ) ) [Nov 11] =&gt; Array ( [0] =&gt; Array ( [minmonth] =&gt; 2011-11-01 [maxmonth] =&gt; 2011-11-01 [nrcheck] =&gt; 91 [data] =&gt; 63.1 ) ) [Dec 11] =&gt; Array ( [0] =&gt; Array ( [minmonth] =&gt; 2011-12-01 [maxmonth] =&gt; 2011-12-01 [nrcheck] =&gt; 89 [data] =&gt; 57.5 ) ) ) </code></pre> <p>)</p> <p>here is a pastebin with var_export as suggested (can't seem to format it propperly here) <a href="http://pastebin.com/b8hYM7TW" rel="nofollow">http://pastebin.com/b8hYM7TW</a> 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).</p> <p>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.</p> <p>I read about recursive functions but I'm still not getting it...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload