1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

ask about count() function

Discussion in 'PHP' started by husniteja, Feb 25, 2005.

  1. #1
    i have exsternal file and try to read that. My exsternal file (config.gb)
    
    check: name,required 
    check: email,required,email-check 
    check: comment,required
    
    Code (markup):
    and in my PHP program i use standard function to open and read the file :
    
    while (!feof($fd)) { 
          $line = fgets($fd, 8192); 
                
          if (ereg("^check:", $line)) { 
    
       $check = explode(",", ereg_replace("check:\ *", "", trim($line))); 
       echo count($check);
       $field = $check[0]; 
       for ($i = 1; $i < count($check); $i++) {
         [B]echo $i; [/B] 
         if (ereg("required", $check[$i])) { 
           $this->required[] = $field; 
         } else if (ereg("email-check", $check[$i])) { 
           $this->checkemail[] = $field; 
         } 
       } 
          } 
    } 
    
    Code (markup):
    i tried to print the value of $i (bold in code) to know what is the resutl, and the result is 1121, i cannot figure out what is mean. Please help me with this
     
    husniteja, Feb 25, 2005 IP
  2. frud0

    frud0 Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You wanna know what the "count" function does? http://www.php.net/count
    It counts the number of elements in an array..

       echo count($check);
       $field = $check[0]; 
       for ($i = 1; $i < count($check); $i++) {
         echo $i;  
    Code (markup):
    Kinda wierd code... first "echo" will tell you the number of elements and the second time it`ll progressively show you that "count"

    I`
     
    frud0, Feb 25, 2005 IP