I have data like this:
$movements = [
array(
"amount" => 100,
"type" => "expense",
"Dates" => "2020-01-01"
),
array(
"amount" => 100,
"type" => "income",
"Dates" => "2020-01-01"
),
array(
"amount" => 200,
"type" => "expense",
"Dates" => "2020-02-01"
),
array(
"amount" => 200,
"type" => "income",
"Dates" => "2020-02-01"
),
array(
"amount" => 300,
"type" => "income",
"Dates" => "2020-03-01"
),
array(
"amount" => 400,
"type" => "expense",
"Dates" => "2020-04-01"
),
array(
"amount" => 400,
"type" => "income",
"Dates" => "2020-04-01"
),
]
I want to separate it into 3 different arrays like so:
//This are my chart labels
$dates = ["2020-01-01","2020-02-01","2020-03-01"."2020-04-01"]
//This are my datapoints
$income = [100,200,300,400]
$expense = [100,200,0,400]
For the life of me i just cant seem to wrap my head around this today, I have tried doing loops and while/if using "array_colum()" but I cant get to add a 0 for the entry that does not have a matching date.
PS: I need the data in that format snice im charting it on chart.js within a Laravel view.
Any help is greatly appreciated.