mardi 2 mars 2021

Creating array variable in collection loop

I get data from query and running a foreach loop on it.

foreach($result as $data)
{
    $myVar[$data->flag][$data->year]['totalActions'] += $data->totalActions;
}

And getting this error Undefined variable: myVar

When I create a variable before loop like $myVar = []

Then it gives me the error Undefined index: All

Here All is value of $data->flag

How to handle this?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3q8L7eM
via IFTTT

Aucun commentaire:

Enregistrer un commentaire