Need Loops for PHP Username/Pass Encryption Script I've created this PHP script to print a batch of usernames with encrypted passwords locally on my computer because the user/pass format is always the same.

username = username
password = username + &quot;admin&quot;
example = homer / homeradmin

Then paste them into two different .htpasswd file and upload to an public Apache server to password-protect a directory and a directory within it.
Is there a better way to write the code below?
&lt;?php
// Password to be encrypted for a .htpasswd file
$user1 = 'admin';
$user2 = 'g';
$user3 = 'homer';
$user4 = 'marge';
$user5 = 'bart';
$user6 = 'lisa';
$user7 = 'maggie';
$user8 = 'dog';


//Admin
$admin1 = 'admin';
$admin2 = '23!bseEsF@';
$admin3 = 'homeradmin';
$admin4 = 'margeadmin';
$admin5 = 'bartadmin';
$admin6 = 'lisaadmin';
$admin7 = 'maggieadmin';
$admin8 = 'dogadmin';

// Encrypt password
$pass1 = crypt($user1, base64_encode($user1));
$pass2 = crypt($user2, base64_encode($user2));
$pass3 = crypt($user3, base64_encode($user3));
$pass4 = crypt($user4, base64_encode($user4));
$pass5 = crypt($user5, base64_encode($user5));
$pass6 = crypt($user6, base64_encode($user6));
$pass7 = crypt($user7, base64_encode($user7));
$pass8 = crypt($user8, base64_encode($user8));


$adminpass1 = crypt($admin1, base64_encode($admin1));
$adminpass2 = crypt($admin2, base64_encode($admin2));
$adminpass3 = crypt($admin3, base64_encode($admin3));
$adminpass4 = crypt($admin4, base64_encode($admin4));
$adminpass5 = crypt($admin5, base64_encode($admin5));
$adminpass6 = crypt($admin6, base64_encode($admin6));
$adminpass7 = crypt($admin7, base64_encode($admin7));
$adminpass8 = crypt($admin8, base64_encode($admin8));
?&gt;

&lt;!doctype html&gt;
  &lt;meta charset=&quot;utf-8&quot;&gt;
  &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge,chrome=1&quot;&gt;
  &lt;title&gt;Encrypt&lt;/title&gt;
  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot;&gt;
  &lt;head&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;p&gt;
&lt;?php
// Print encrypted password
echo $user1 . &quot;:&quot; . $pass1 . &quot;&lt;br/&gt;&quot;;
echo $user2 . &quot;:&quot; . $pass2 . &quot;&lt;br/&gt;&quot;;
echo $user3 . &quot;:&quot; . $pass3 . &quot;&lt;br/&gt;&quot;;
echo $user4 . &quot;:&quot; . $pass4 . &quot;&lt;br/&gt;&quot;;
echo $user5 . &quot;:&quot; . $pass5 . &quot;&lt;br/&gt;&quot;;
echo $user6 . &quot;:&quot; . $pass6 . &quot;&lt;br/&gt;&quot;;
echo $user7 . &quot;:&quot; . $pass7 . &quot;&lt;br/&gt;&quot;;
echo $user8 . &quot;:&quot; . $pass8 . &quot;&lt;br/&gt;&quot;;
?&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;?php
echo $admin1 . &quot;:&quot; . $adminpass1 . &quot;&lt;br/&gt;&quot;;
echo $admin2 . &quot;:&quot; . $adminpass2 . &quot;&lt;br/&gt;&quot;;
echo $admin3 . &quot;:&quot; . $adminpass3 . &quot;&lt;br/&gt;&quot;;
echo $admin4 . &quot;:&quot; . $adminpass4 . &quot;&lt;br/&gt;&quot;;
echo $admin5 . &quot;:&quot; . $adminpass5 . &quot;&lt;br/&gt;&quot;;
echo $admin6 . &quot;:&quot; . $adminpass6 . &quot;&lt;br/&gt;&quot;;
echo $admin7 . &quot;:&quot; . $adminpass7 . &quot;&lt;br/&gt;&quot;;
echo $admin8 . &quot;:&quot; . $adminpass8 . &quot;&lt;br/&gt;&quot;;
?&gt;
&lt;/p&gt;

&lt;/body&gt;
&lt;/html&gt;
the first thing that came to my mind to make this cleaner was an array or rather several arrays.

maybe something like this:

$user = array('admin','g','homer','marge','bart','lisa','maggie','dog');
$admin = array('admin','23!bseEsF@','homeradmin','margeadmin','bartadmin','maggieadmin','dogadmin');

$password = array(8); //my syntax may be wrong here
$adminPassword = array(8); //my syntax may be wrong here

for ($x=0; $x &lt; count($user); x$++)
{
    $password[$x] = crypt($user[$x], base64_encode($user[$x]));
    $adminPass[$x] = crypt($admin[$x], base64_encode($admin[$x]));
}


And then your Echo's would look like this.

echo $user1 . ":" . $pass1 . "&lt;br/&gt;";
for ($y=0; $y &lt; count($user); $y++)
{
    echo $user[$y] . ":" . $pass[$y] . "&lt;br/&gt;";
}
for ($z=0; $z &lt; count($admin); $z++)
{
    echo $admin[$z] . ":" . $adminPass[$z] . "&lt;br/&gt;";
}


The only way that this works is if all the arrays are the same length and arrays in PHP are base 0. otherwise you have to change the for declarations a little bit.



Again I say that my Syntax may not be perfect or even well formed,  but this is much cleaner than what you have. 

Syntax not Guaranteed