0๐
โ
So I figured it out. I just had to add an array initializing it. Here is the code:
$t = [0,0,0];
foreach ($projects as $project) {
if($project->stage === 'Waiting') {
$t[0] = $project->total;
} elseif($project->stage === 'In Progress') {
$t[1] = $project->total;
} elseif($project->stage === 'Launched') {
$t[2] = $project->total;
} else {
$t[] = $t;
}
}
$t = json_encode($t);
Source:stackexchange.com