Note that there are some explanatory texts on larger screens.

plurals
  1. POadd key to array with value generated based on current position of array
    text
    copied!<p>What i used:</p> <pre><code> $maxpoints = 40; for($i = 0; $i &lt; count($trainergross); $i++){ $trainergross[$i]['points'] = $maxpoints; $maxpoints -=2; } </code></pre> <p>heres my sort function:</p> <pre><code>function grossSort($gross, $compare) { if($gross['gross'] &gt; $compare['gross']) return -1; // move up else if($gross['gross'] &lt; $compare['gross']) return 1; // move down else return 0; // do nothing } </code></pre> <p>This is tricky (for me at least). I need to generate a points system based on the highest value gross degrading by 2.</p> <p>here is my array after running a function to sort it by highest gross (<code>$trainergross</code>): </p> <pre><code>Array ( [0] =&gt; Array ( [instr] =&gt; blah [club] =&gt; Colvin [gross] =&gt; 2146 [bud] =&gt; 0 [ratio] =&gt; 0 ) [1] =&gt; Array ( [instr] =&gt; rob [club] =&gt; Evans [gross] =&gt; 2000 [bud] =&gt; 0 [ratio] =&gt; 0 ) [2] =&gt; Array ( [instr] =&gt; new [club] =&gt; Boulevard [gross] =&gt; 930 [bud] =&gt; 755 [ratio] =&gt; 248 ) [3] =&gt; Array ( [instr] =&gt; test [club] =&gt; Boulevard [gross] =&gt; 805 [bud] =&gt; 50 [ratio] =&gt; 50 ) [4] =&gt; Array ( [instr] =&gt; lee [club] =&gt; Boulevard [gross] =&gt; 235 [bud] =&gt; 60 [ratio] =&gt; 30 ) [5] =&gt; Array ( [instr] =&gt; rob [club] =&gt; Boulevard [gross] =&gt; 175 [bud] =&gt; 125 [ratio] =&gt; 125 ) [6] =&gt; Array ( [instr] =&gt; rob [club] =&gt; Henrietta [gross] =&gt; 60 [bud] =&gt; 0 [ratio] =&gt; 0 ) ) </code></pre> <p>In this example <code>$trainergross[0]</code> should get a <code>key =&gt; value</code> of <code>"points" =&gt; 40</code></p> <p><code>$trainergross[1]</code> would get 38.. [2] would get 36... etc.</p> <p>I would then usort the array by bud, then do it again increasing the value key based on highest bud.</p> <p>My issue is, i dont even know where to start with doing this. Is it possible to add a key based on the order of the array?</p> <p>The only thought i have is doing 3 different arrays then merging them all, but that seems terribly inefficient.</p> <p>Sorry for vague, dont really even know how to ask, hopefully this explained it well enough.</p>
 

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