Hey Guys,
I have a 'spinning' code where each time a script runs - $user = a random username (from a list of about 5)
what I need, is to know how to get something along the lines of:
IF $user = 'username1'
THEN
$password = 'password1'
IF $user = 'username2'
THEN
$password = 'password2'
etc. Thanks for your help!
is $this = 'that' then $that = 'this'... How do I?
Moderator: General Moderators
-
shanehunter
- Forum Commoner
- Posts: 30
- Joined: Sun Jun 27, 2010 3:43 pm
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: is $this = 'that' then $that = 'this'... How do I?
You can do it the long way like you showed:
However, it might be easier to use an array to lookup the values. Then you don't have to keep adding code, just more username/password pairs to the data:
Code: Select all
if ($user == 'username1') {
$password = 'password1';
} elseif ($user == 'username2') {
$password = 'password2';
}Code: Select all
$passwords = array(
'username1' => 'password1',
'username2' => 'password2',
);
if (isset($passwords[$user])) {
$password = $passwords[$user];
}(#10850)
-
shanehunter
- Forum Commoner
- Posts: 30
- Joined: Sun Jun 27, 2010 3:43 pm
Re: is $this = 'that' then $that = 'this'... How do I?
awesome!
thank you! =)
thank you! =)