Arrays, logins, forms and confusion

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!

:slight_smile:

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


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.