Add values from a php string

Asked

Viewed 1,598 times

0

I have the following code:

foreach ($class->ListaChave($CdLote) as $dados) {
   var_dump($dados->getQvol());
}

Exit:

string(1) "1"

string(1) "1"

string(1) "2"

string(1) "1"

I need these values to be summed up and returned to me the value within a variable.

1 answer

1


You can make the sum normally. But if you want to ensure that the return of getQVol() always be whole, and do not have access to class to change, you can do so:

<?php
$soma = 0;
foreach ($class->ListaChave($CdLote) as $dados) {
   $soma += (int) $dados->getQvol();
}

echo $soma;
  • All right, I was traveling and forgot the obvious hehehe.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.