0

I have a function that counts the number of variables equal to one other, I used the technique in php for each, with $i = 1 and whenever they find $i++. My problem is that I would display the results, but now, if I have four results, it displays 1 2 3 4. How do you display only the total result?

PHP code :

if(!empty($myvar)) {
    $i = 1;
    foreach ($identity as $ent) { 
        if(($ent->name) === ($myvar->name)) {
            echo $i;
            $i++; 
        } 
    }
}
ale
  • 11,636
  • 27
  • 92
  • 149
Tomaw
  • 165
  • 3
  • 5
  • 17

1 Answers1

8
if(!empty($myvar)) {
    $i = 1;
    foreach ($identity as $ent) { 
        if(($ent->name) === ($myvar->name)) {
             $i++; 
        } 
    }
    echo $i;
}
ale
  • 11,636
  • 27
  • 92
  • 149
  • No worries.. it gets easier ;). Please mark as solved IF you're happy with the solution. – ale Feb 20 '12 at 17:10