0

Given that I have generated array of date, sales and type(customer,partner):

array(5) {
  [0]=>
  array(3) {
    ["date"]=>
    string(19) "25/03/2019 12:00 am"
    ["sales"]=>
    string(2) "95"
    ["type"]=>
    string(8) "customer"
  }
  [1]=>
  array(3) {
    ["date"]=>
    string(18) "25/03/2019 1:00 pm"
    ["sales"]=>
    string(5) "112.5"
    ["type"]=>
    string(8) "customer"
  }
  [2]=>
  array(3) {
    ["date"]=>
    string(18) "25/03/2019 1:20 pm"
    ["sales"]=>
    string(5) "132.5"
    ["type"]=>
    string(8) "customer"
  }
  [3]=>
  array(3) {
    ["date"]=>
    string(18) "25/03/2019 3:10 pm"
    ["sales"]=>
    string(2) "19"
    ["type"]=>
    string(7) "partner"
  }
  [4]=>
  array(3) {
    ["date"]=>
    string(18) "25/03/2019 4:07 pm"
    ["sales"]=>
    string(3) "7.5"
    ["type"]=>
    string(7) "partner"
  }
}

and I want to arrange it into something like this in table form: enter image description here

If the date object is within the range of first week of the month it will get those date and add the sales of customer and partner. However, the column of customer and partner must be separated by column, then get the sum of customer and partner column to get the total on the 4rth column.

I found something on this post but it didn't help me out PHP get number of week for current month only using php.

Nikko Dela Cruz
  • 42
  • 2
  • 10
  • It is better to place images into the question than to use an off site image store – RiggsFolly Mar 26 '19 at 13:49
  • 3
    What is your attempt? What is the result? How does it differ from what you want? – Patrick Q Mar 26 '19 at 13:49
  • Does this data originate in a database? It might be easier to achieve using a SQL aggregate query. – ADyson Mar 26 '19 at 14:10
  • @ADyson, no, it is from API – Nikko Dela Cruz Mar 26 '19 at 14:25
  • 1
    Ok, it was worth asking... So the next thing: "I want" is not a question, nor a problem statement. What have you reserched? What have you tried? Where are you stuck? What would you like help with? Unless it's fairly simple, you're very unlikely to get someone write out the whole solution for you. This isn't a free tutorial or outsourcing service...we like to _help_ you, not _replace_ you. Thanks. – ADyson Mar 26 '19 at 14:26
  • P.S. your data sample is not a particularly good one because everything is on one day, and would all be grouped together. It doesn't allow for testing of the code grouping data into different sets. – ADyson Mar 26 '19 at 14:28
  • 1
    Basically you want to implement what’s called a [control break](https://en.wikipedia.org/wiki/Control_break). Your data needs to be appropriately sorted, then you loop over it and check if you are still in the same week as you were when working on the previous record. Based on that, you decide what needs to be done - keep summing up the values you are interested in, or output the table row for the week. – 04FS Mar 26 '19 at 14:31

0 Answers0