Results 1 to 6 of 6

Thread: [php]loop-de-loop

  1. #1

    [php]loop-de-loop

    Hello,

    The following code snippet, traveses (2) arrays, checking for a match. I understand the first loop through ($usernames), but where is the interation called on ($passwords)?
    Code:
     
    // Now we loop through each entry in our arrays looking for a valid match
        for ($count = 0; $count < count($usernames) && $matchFound == false; $count++) {
    
            // If username and password matches entry...
            if ($username == $usernames[$count] && $password == $passwords[$count]) {
    
                // Get the user's message and indicate we've found a match
                $message = $messages[$count];
                $matchFound = true;
            }
        }

  2. #2
    i think that the $password var is already set, and it checks the number of the password to the number of the username? i think that code should work

    PHP Code:
     // Now we loop through each entry in our arrays looking for a valid match
        
    for ($count 0$count count($usernames) && $matchFound == false$count++) {

            
    // If username and password matches entry...
            
    if ($username == $usernames[$count] && $password == $passwords[$count]) {

                
    // Get the user's message and indicate we've found a match
                
    $message $messages[$count];
                
    $matchFound true;
            }
    else {
    echo 
    "No match at interval {$count}";
    }
        } 
    that will tell u where there will be an error

  3. #3
    Hi,

    Thanks the current code does work, its from Foundation PHP for FLASH. My question was why this loop goes through (2) arrays, and a second one is not needed for $password.

  4. #4
    Quote Originally Posted by cki
    Hi,

    Thanks the current code does work, its from Foundation PHP for FLASH. My question was why this loop goes through (2) arrays, and a second one is not needed for $password.
    because the snippet checks through 2 arrays to see if it can find a message.. thats what it says

  5. #5
    Hi,

    I've been attempting the same thing with AS, and have hit a snag.
    AS
    Code:
    matchfound = false;
    var message = new Array("Fun", "Love", "Laugh");
    var user = new Array("Alice", "Shelia", "Cathy");
    var pass = new Array("Disco", "Tango", "Samba");
    for (var i = 0; i<user.length && matchfound == false; i++) {
    	//IF USERNAME AND PASSWORD MATCHES ENTRY...
    	if (users == user[i] && password == pass[i]) {
    		trace(user[i]);
    		trace(pass[i]);
    		
    		//GET THE USER'S MESSSAGE AND INDICATE WE'VE FOUND A MATCH
    		var messages = message[i];
    		trace(messages[i]);
    		matchfound = true;
    	}
    }

  6. #6


    Code:
    matchfound = false;
    var message = new Array("Fun", "Love", "Laugh");
    var user = new Array("Alice", "Shelia", "Cathy");
    var pass = new Array("Disco", "Tango", "Samba");
    for (i = 0; i<user.length && matchfound == false; i++) {
    //IF USERNAME AND PASSWORD MATCHES ENTRY...
    if (users == user[i] && password == pass[i]) {
    trace(user[i]);
    trace(pass[i]);
    
    //GET THE USER'S MESSSAGE AND INDICATE WE'VE FOUND A MATCH
    var messages = message[i];
    trace(messages[i]);
    matchfound = true;
    }
    }
    u dont need var i =0 just i=0 will do

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012