I am trying to loop and display all the contents of my array, but the problem is, when I use a counter, the code only returns the first letter of the first index word in the array and if I removed the counter, only the first index of the array is displayed.
This is my code:
$query = $this->chartsData->missingPerRegion();
$region_name = array();
$missing_num = array();
$count = 0;
foreach($query->result_array() as $row){
$regionQuery = $this->chartsData->getRegions($row['affected-population_region_id']);
foreach($regionQuery->result_array() as $region){
$region_name = $region['name'];
}
$missing_num = $row['missing'];
}
while($count < count($region_name) && $count < count($missing_num)){
echo '{"label": "' . $region_name[$count] . '", "value": ' . $missing_num[$count] . '},';
// Outputs '{"label": "R", "value": 0},'
// Expected Output: '{"label: "Region X", "value": 0}, {"label: "RegionXI", "value": 10}, ...'
$count++;
}
Anyone who knows how to solve this problem?