0

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);
5
  • Just use dd(count($nb_quota_lic_simples));! Commented Jul 6, 2017 at 12:09
  • thnaks for your reply when i do dd($nb_quota_lic_simples); i get 30 and when i do dd(count($nb_quota_lic_simples)) i get = 1 ! i should get 60 . why ? Commented Jul 6, 2017 at 12:11
  • Just do $nb_quota_lic_simples += $equipe->catg_equipe->nb_licences; Commented Jul 6, 2017 at 12:12
  • i get Undefined variable 'nb_quota_lic_simples' when i do $nb_quota_lic_simples += $equipe->catg_equipe->nb_licences inside the foreach Commented Jul 6, 2017 at 12:13
  • dd(count($nb_quota_lic_simples)) gives you total number of result of $nb_quota_lic_simples Commented Jul 6, 2017 at 12:13

1 Answer 1

3

try something like this

    $total = 0;
    foreach ($equipes as $equipe) {
        $total += $equipe->catg_equipe->nb_licences;               
    }
    dd($total);
Sign up to request clarification or add additional context in comments.

1 Comment

i will accept the answer in 5 min when i can click on it !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.