Note that there are some explanatory texts on larger screens.

plurals
  1. POrecursive dynamic array
    primarykey
    data
    text
    <p>I have this php array scenario:</p> <pre><code>array(2) { [43]=&gt; array(2) { ["2011-07-01"]=&gt; int(20) ["2011-07-02"]=&gt; int(16) } [77]=&gt; array(2) { ["2011-07-01"]=&gt; int(10) ["2011-07-02"]=&gt; int(10) } } </code></pre> <p>whereas array($person=>array(date=>hour)). I need to distribute 8 hours into per subsequent days, so the output would be:</p> <pre><code>array(2) { ["anna"]=&gt; array(5) { ["2011-07-01"]=&gt; int(8) ["2011-07-02"]=&gt; int(8) ["2011-07-03"]=&gt; int(8) ["2011-07-04"]=&gt; int(8) ["2011-07-05"]=&gt; int(4) } ["joan"]=&gt; array(3) { ["2011-07-01"]=&gt; int(8) ["2011-07-02"]=&gt; int(8) ["2011-07-03"]=&gt; int(4) } } </code></pre> <p>any ideas on how to do this? here's just a fragment, the production array is very large, avg 50 person keys and dozens of date keys, and the primary function we got here took 2-3 mins to do the trick.</p> <p>btw, to post here i've exhausted searching and coding.</p> <p>thank u!</p> <hr> <p>From a comment by the author from below:</p> <p>I've tried looping thru the array an populate a new one, tried to (re)populate the same array into foreach loop (but add a item inside loop does cause the pointer to be extended),tried iterators to manipulate the array actual main function is:</p> <pre><code>function Distribute($u,$h,$d,$m,$y,$arr,$u_h=8) { $remain = ($h % $u_h);$h = $h-$remain; $total_days = ($h/$u_h); if ($total_days &gt; 0) for ($i=0; $i&lt;$total_days ; $i++) $arr[date('m-Y',mktime(0,0,0,$m,$d+$i,$y))][$u] += $u_h; if ($remain &gt; 0) $arr[date('m-Y',mktime(0,0,0,$m,$d+$i,$y))][$u] += $remain; return $arr; } </code></pre> <p>it works, but is pretty slow.</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.
    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