I have this month of the month $monthsNum = ['1','2','3','4','5','6','7','8','9','10','11','12'];and I want it to be compared in the month_uploaded database column with values from 1 to 12. I want it to count the number of instances of the values of the $ monthNum array in the month_uploaded column and store it in the $ count_uploads array . placed with a null value in the $ count_uploads array. How should I do it? Your help is greatly appreciated. Thank. Below are snippets of my codes.

function count_uploads_perMonth(){
$monthsNum = ['1','2','3','4','5','6','7','8','9','10','11','12'];
$query = $this->db->select("*")
->from($this->table_par)
->where_in("month_uploaded",$monthsNum)
->get();
foreach( $query->result() as $row ){
$count_uploads[] = count($row->month_uploaded);
}
var_dump($count_uploads);
}
Output: False
array (size=5)
0 => int 1
1 => int 1
2 => int 1
3 => int 1
4 => int 1
Output Required:
array (size=12)
0 => 0 or null
1 => 0 or null
2 => 0 or null
3 => 0 or null
4 => 0 or null
5 => 1
6 => 3
7 => 0 or null
8 => 0 or null
9 => 0 or null
10 => 0 or null
11 => 0 or null
This is closer, you just need to get the correct count value for each array key
function count_uploads_perMonth(){
$monthsNum = array('1','2','3','4','5','6','7','8','9','10','11','12');
$this->db->select("month_uploaded as cnt");
$this->db->where_in('month_uploaded',$monthsNum);
$this->db->group_by('month_uploaded');
$query = $this->db->get($this->table_par);
$count_uploads = array_fill(1, 12, 0);
foreach( $query->result() as $row ){
$count_uploads[$row->cnt] = $row->cnt;
}
var_dump($count_uploads);
}
Output:
array (size=12)
1 => int 0
2 => int 0
3 => int 0
4 => int 0
5 => int 0
6 => string '6' (length=1) --- value should be 1 and length is 1
7 => string '7' (length=1) --- value should be 4 and length is 4
8 => int 0
9 => int 0
10 => int 0
11 => int 0
12 => int 0