Mathieu Mourareau
Mathieu Mourareau

Reputation: 1220

foreach loop count function total

I would like to make a total count on my variable : $nb_quota_lic_simples

In the foreach i check how many free licences i have, i would like to get the total of the licences if there is many equipes. Hope someone help me. Thanks a lot in advance !

Actually i have :

foreach ($equipes as $equipe) {
    $nb_quota_lic_simples = $equipe->catg_equipe->nb_licences;               
}
dd($nb_quota_lic_simples);

Upvotes: 0

Views: 487

Answers (1)

David
David

Reputation: 1889

try something like this

    $total = 0;
    foreach ($equipes as $equipe) {
        $total += $equipe->catg_equipe->nb_licences;               
    }
    dd($total);

Upvotes: 3

Related Questions