Chartjs-Chart JS + Laravel โ€“ How to add 0 to array

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);

Leave a comment