Array question

I created an array of usernames and passwords and have a simple script working like this:

$user_name = "bob";
echo "username: $user_name <br/>";
echo "password: ".array_search($user_name,$a);

This works fine, but I need to share “bills” username and password with “sarah”… so I am looking at something like this so that if the 3rd key/column is sarah it will show bills username and password:

$user_name = "sarah";
echo "username: $user_name <br/>";
echo "password: ".array_search($user_name,$a);

Is this possible?

Plain text passwords should never be stored or available. As far as question, the array structure would need to be changed to just key value pairs.

$user_name = "sarah"; 
    "bob" => array(
         "password" => "password1"
        ,"access_to" =>    "john"),
    "bill" => array(
         "password" => "password2"
        ,"access_to" =>    "bob"),    
    "sarah" => array(
         "password" => "password3"
        ,"access_to" =>    "bill")
echo "<pre>";
echo "</pre>"; 

$user_password   = (array_key_exists($user_name,$a) ? $a[$user_name]['password'] : '');
$access_name     = (array_key_exists($user_name,$a) ? $a[$user_name]['access_to'] : '');
$access_password = (array_key_exists($access_name,$a) ? $a[$access_name]['password'] : '');

echo "username: ". $user_name . "<br />";
echo "password: ". $user_password . "<br />";
echo "access name: ". $access_name . "<br />";
echo "access password: ". $access_password . "<br />";

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.