# Arrays, logins, forms and confusion

**URL:** <https://forum.kirupa.com/t/arrays-logins-forms-and-confusion/265593>\
**Category:** Uncategorized\
**Created:** [July 10, 2008, 3:37pm UTC](https://forum.kirupa.com/t/arrays-logins-forms-and-confusion/265593 "2008-07-10T15:37:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![captaincaveman](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@captaincaveman](https://forum.kirupa.com/u/captaincaveman)\
**Post date:** [July 10, 2008, 3:37pm UTC](https://forum.kirupa.com/t/arrays-logins-forms-and-confusion/265593/1 "2008-07-10T15:37:50Z")

</div>

hi all,

Got a problem with arrays that im not too sure about.

Basically im using an array to pre-populate an input field depending on what the users logged in as.

For example, i’ve put in array each user and their corresponding country which i want to stick in the form.

so…

$country = array (“user1” =\> “england”, “user2” =\> “australia”); etc etc…

What i need to do is to find out what user is logged in (from an outside variable) and compare it to whats in the array and echo out the correct country in form…

Im very stuck on this so any ideas and help would be very much appreciated!

🙂

---

<div class="post-metadata">

**Author:** ![jwilliam](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jwilliam](https://forum.kirupa.com/u/jwilliam)\
**Post date:** [July 10, 2008, 8:04pm UTC](https://forum.kirupa.com/t/arrays-logins-forms-and-confusion/265593/2 "2008-07-10T20:04:35Z")

</div>

Do you already have the user variable set? If so, then do this:

```auto

if(array_key_exists($user, $country)) {
  echo $country[$user];
} else {
  echo 'That user was not found.';
}

```

Where $user is the variable that contains the user (“user1”, “user2”, etc…). If you’re trying to find out how to get the information from the user, you’ll have to use a form in some manner… Google this. There’s tons of stuff out there on forms.
