0

I have 2 muldimensional arrays. the first from database(example values), another as an date interval(exmple dates, can be much bigger). I need to generate a third array that fills the dates gap from the first one, note that the value of the key "agent" changes.

php5, sqlServer, pdo connection

<?php
$array_sellers = array(
        array(
            'agent'=>1,
            'date' =>'2019-01-01',
            'sales' =>2
            ),
        array(
            'agent'=>1,
            'date' =>'2019-01-02',
            'sales' =>4
            ),
        array(
            'agent'=>2,
            'date' =>'2019-01-03',
            'sales' =>1
            ),
        );
$array_dates = array('2019-01-01','2019-01-02','2019-01-03');
//output array
$output =  array(
        array(
            'agent'=>1,
            'date' =>'2019-01-01',
            'sales' =>2
            ),
        array(
            'agent'=>1,
            'date' =>'2019-01-02',
            'sales' =>4
            ),
        array(
            'agent'=>1,
            'date' =>'2019-01-03',
            'sales' =>0
            ),
        array(
            'agent'=>2,
            'date' =>'2019-01-01',
            'sales' =>0
            ),
        array(
            'agent'=>2,
            'date' =>'2019-01-02',
            'sales' =>0
            ),
        array(
            'agent'=>2,
            'date' =>'2019-01-03',
            'sales' =>1
            ),
        );
?>
James Z
  • 12,209
  • 10
  • 24
  • 44
  • Create an array with all the dates first, then merge that with the other array. The array in the second argument will overwrite the first. maybe us `array_replace_recursive` -- I don't understand what this means `I need to generate a third array that fills the dates gap from the first one` can you provide an example of the desired output. For example, do you mean fills them from the second array to the first array? – ArtisticPhoenix May 21 '19 at 00:55
  • https://meta.stackoverflow.com/questions/326569/under-what-circumstances-may-i-add-urgent-or-other-similar-phrases-to-my-quest – Nick May 21 '19 at 00:59
  • `$array_sellers` looks like the output from a database query. You might find it easier to just modify the query to produce output regardless of whether an agent had sales or not. For an example, see [this answer](https://stackoverflow.com/questions/56223598/adding-zero-to-an-array-if-empty-values-occurs-in-array/56223717#56223717) – Nick May 21 '19 at 01:01
  • I would like to have the output that is in the code. The idea is to build a html table and export that as xls(csv) file, using php and appropriate headers – Jorge Carvalho May 21 '19 at 01:35
  • I cant use the query solution because some sellers might leaved the company between dates range and need to fill the gaps – Jorge Carvalho May 21 '19 at 08:10

0 Answers0