Note that there are some explanatory texts on larger screens.

plurals
  1. POFill missing date and prices (such as weekend) in array
    primarykey
    data
    text
    <p>I have an array with "gaps" like this:</p> <pre><code>$arr = array ( "bananas" =&gt; array ( "2010-01-01" =&gt; "10.1", "2010-01-02" =&gt; "11.4", "2010-01-05" =&gt; "13.3", //missing 03, 04 "2010-01-06" =&gt; "09.2", "2010-01-07" =&gt; "11.1" ), "grapes" =&gt; array ( "2011-01-05" =&gt; "20.1", "2011-01-06" =&gt; "21.4", "2011-01-07" =&gt; "23.3", "2011-01-08" =&gt; "29.2", "2011-01-10" =&gt; "21.1", //missing 09 "2011-01-11" =&gt; "21.0" ), "coconuts" =&gt; array ( "2012-01-28" =&gt; "50.1", "2012-01-29" =&gt; "51.4", "2012-02-02" =&gt; "53.3", //missing 30, 31, 01 "2012-02-03" =&gt; "51.1" ) ); </code></pre> <p>I don't know how many products and "date=>price" are there in an array.<br/> How I can fill missing date(s) with last price before gap?</p> <p><strong>Important:</strong> dates can be in different months (look at <code>"coconuts"</code>).</p> <p>I want the result to be like this:</p> <pre><code>$arr = array ( "bananas" =&gt; array ( "2010-01-01" =&gt; "10.1", "2010-01-02" =&gt; "11.4", //was last price before gap "2010-01-03" =&gt; "11.4", //filling missing "2010-01-04" =&gt; "11.4", //filling missing "2010-01-05" =&gt; "13.3", "2010-01-06" =&gt; "09.2", "2010-01-07" =&gt; "11.1" ), "grapes" =&gt; array ( "2011-01-05" =&gt; "20.1", "2011-01-06" =&gt; "21.4", "2011-01-07" =&gt; "23.3", "2011-01-08" =&gt; "29.2", //was last price before gap "2011-01-09" =&gt; "29.2", //filling missing "2011-01-10" =&gt; "21.1", "2011-01-11" =&gt; "21.0" ), "coconuts" =&gt; array ( "2012-01-28" =&gt; "50.1", "2012-01-29" =&gt; "51.4", //was last price before gap "2012-01-30" =&gt; "51.4", //filling missing "2012-01-31" =&gt; "51.4", //filling missing "2012-02-01" =&gt; "51.4", //filling missing "2012-02-02" =&gt; "53.3", "2012-02-03" =&gt; "51.1" ) ); </code></pre> <p>Thank you for your time.</p>
    singulars
    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.
 

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