Hello Good evening, I have this code
$total = array();
$months = array(1,2,3,4,5,6,7,8,9,10,11,12);
foreach ($months as $value) {
foreach ($total_clients as $clientes) {
if($value == $clientes->month){
$total[$value] = (int)$clientes->total;
} else {
$total[$value] = 0;
}
}
}
The variable $total_clientes
has these values
$total_clients = array(
array(
'month' => 5
'total => 6
),
array(
'month' => 7
'total => 12
),
array(
'month' => 11
'total => 89
),
)
What I need is that the array $total
be filled only with the values of $total_clientes
depending on the index in $months
taking as reference the key 'month' of the array $total_clients
something like that $total[0,0,0,0,6,0,12,0,0,0,89,0];
only this gives me 'Array
(
[1] => 0
[2] => 0
[3] => 0
[4] => 0
[5] => 0
[6] => 0
[7] => 0
[8] => 0
[9] => 0
[10] => 0
[11] => 89
[12] => 0
)
'
I can not get it to fill properly, I made prints of the loops but they do not work the way I need to, they can give me a hand, thank you.
I need that to be able to pass it to a customer graph for months.