Suppose I have some value like this
Array
(
[0] => stdClass Object
(
[amount] => 4000.00
[monthyear] => 2018-02
)
[1] => stdClass Object
(
[amount] => 5000.00
[monthyear] => 2018-01
)
)
I want to generate some value like this
[5000,4000,0,0,0,0,0,0,0,0,0,0]
I used foreach loop and for loop but I can't understand how to do this, it's actually generating a sum of balance report by month.
Is it possible to generate this value via CodeIgniter?
My query for the above output is:
$this->cm->select_sum = "amount";
$this->cm->select = "DATE_FORMAT(date,'%Y-%m') as monthyear";
$this->cm->table_name = "personal_balance";
$this->cm->where = array("DATE_FORMAT(date,'%Y')" => date('Y'));
$this->cm->group_by = "DATE_FORMAT(date,'%m')";
$balance = $this->cm->get();
[5000, 4000]by iterating over the existing. Then you can use array_pad() to extend the new array with '0's to the desired length.