count($_GET=="yes") ???

Discussion in 'PHP' started by Fracisc, Mar 1, 2009.

  1. #1
    I need to count how many variables value is set to "yes".

    I have test=yes, stuff=no, bla=yes. I need to count how many of "yes" are set. How can I do that?
     
    Fracisc, Mar 1, 2009 IP
  2. indi.anupam

    indi.anupam Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    set a counter write a for/foreach loop, test value using if and increase the counter. and there you get the number of 'yes' in your $_GET array simple :)

    
    $counter = 0;
    foreach($_GET as $key=>$value)
    {
            $counter = ($value=='Yes')? $counter++:$counter;
    }
    echo $counter;
    
    PHP:
     
    indi.anupam, Mar 1, 2009 IP
  3. SISKO

    SISKO Peon

    Messages:
    9
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    try this

    foreach($_GET as $key=>$value){
    if($value==yes){$count++;}
    }

    echo $count;

    edit: damn..too late :p
     
    SISKO, Mar 1, 2009 IP
  4. Fracisc

    Fracisc Well-Known Member

    Messages:
    3,670
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    195
    #4
    Thanks folks, yeah, bother were late, I already figured it out, but hey, maybe there are others who will also need this.
    Thanks again.
     
    Fracisc, Mar 1, 2009 IP