SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to search for one element in multi-dimension array?

    Let say I have an array like this:
    PHP Code:
     $USER_INFO[1][USERNAME] = "user1";
     
    $USER_INFO[1][PASSWORD] = "password";
     
    $USER_INFO[1][ROOT] = "/home/account/public_html/path";
     
    $USER_INFO[1][URL] = "http://www.domain/path";
     
    $USER_INFO[1][UPLOAD] = 1;
     
    $USER_INFO[1][ADMIN] = 1;

     
    $USER_INFO[2][USERNAME] = "user2";
     
    $USER_INFO[2][PASSWORD] = "password";
     
    $USER_INFO[2][ROOT] = "/home/account/public_html/test";
     
    $USER_INFO[2][URL] = "http://www.domain.com/test";
     
    $USER_INFO[2][UPLOAD] = 1;
     
    $USER_INFO[2][ADMIN] = 1
    What I want to do is search to see if a given username/password (from a submit form) are located in this array.

    Anyone know a good way to do this? I'm trying to do it with a bunch of foreach loops, but was hoping there is a better/easier way.

    Thanks!

  2. #2
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    texas
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this what you're lookin for?
    Code:
    $success = false;
    foreach($USER_INFO as $user){
      if($user[USERNAME] == $username && $user[PASSWORD] == $password){
         $success = true;
      }
    }
    free online calendar: http://inversiondesigns.com
    includes multiple calendars/users/groups, task manager,
    email and sms reminders, permissions (sharing), etc.

  3. #3
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect. Thanks!

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    texas
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    glad to help
    free online calendar: http://inversiondesigns.com
    includes multiple calendars/users/groups, task manager,
    email and sms reminders, permissions (sharing), etc.


Bookmarks

Posting Permissions

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