Create an array of pairs from the consecutive lines, then combine the column of keys with the column of values:
$chunks = array_chunk(
file('userpass.txt', FILE_SKIP_EMPTY_LINES|FILE_IGNORE_NEW_LINES),
2
);
$users = array_combine(
array_column($chunks, 0),
array_column($chunks, 1)
);
Explanation
$chunks
is an array of arrays: each inner array has two elements: #0 is the username (first line) and #1 is the password (second line). Using file
to skip blank lines and remove trailing new-lines keeps this code simple, but not bullet-proof.
$users
then is made by taking all the usernames (index 0
from all the inner arrays) and pointing them to all the passwords (index 1
).
You can accomplish the same with a loop over $chunks
. However, I prefer this approach because all looping is handled inside the engine, where it is marginally more performant.