I have an array $d_visitors = array_count_values($d_visitors);
array:7 [▼
2 => 4
5 => 1
8 => 2
3 => 1
1 => 2
9 => 3
0 => 2
]
I'm trying to loop through that array 24 times, and check if the key matches, and store its value.
$dv = [];
for ($i = 0; $i < 24; $i++){
foreach ($d_visitors as $k =>$v) {
if($i == $k ){
$dv[$i] = $v;
}else{
$dv[$i] = 0;
}
}
}
I'm trying to print out something like this:
array:24 [▼
0 => 2
1 => 2
2 => 4
3 => 1
4 => 0
5 => 1
6 => 0
7 => 0
8 => 2
9 => 3
10 => 0
11 => 0
12 => 0
13 => 0
14 => 0
15 => 0
16 => 0
17 => 0
18 => 0
19 => 0
20 => 0
21 => 0
22 => 0
23 => 0
]
But I kept getting this:
array:24 [▼
0 => 2
1 => 0
2 => 0
3 => 0
4 => 0
5 => 0
6 => 0
7 => 0
8 => 0
9 => 0
10 => 0
11 => 0
12 => 0
13 => 0
14 => 0
15 => 0
16 => 0
17 => 0
18 => 0
19 => 0
20 => 0
21 => 0
22 => 0
23 => 0
]