Reputation: 91
I am making for myself a script that checks how many mH/hash of my miners on mining pool websites are. Therefor I have a bunch of variables with $user and $pass for each site. Example:
$user1 = 'A';
$pass1 = 'B'
$user2 = 'C';
$pass2 = 'D';
So I made a PHP curl that login the form and checks the currently mH/hash. Also I've made a counter, to rise the variable user1 and pass1 up by +1.
$count = 0;
$count = $count + 1;
$user = "$user$count";
echo $user;
But the problem is my output at the login form:
$user2
Should be:
C
I hope it is clear what I am looking for and thanks in advance.
Upvotes: 1
Views: 69
Reputation: 937
I think it would be a better approach to specify your user and password pairs in an array:
$login_info = array();
$login_info[] = array(
'name' => 'A',
'pass' => 'B',
);
$login_info[] = array(
'name' => 'C',
'pass' => 'D',
);
And you can travers the array by foreach:
foreach ($login_info as $info) {
$name = $info['name'];
$pass = $info['pass'];
...
}
You can easily add new elements to the array without creating new variables.
Upvotes: 0
Reputation: 6932
Use an Array:
$user = [];
$pass = [];
$user[1] = 'A';
$pass[1] = 'B'
$user[2] = 'C';
$pass[2] = 'D';
$count = 0;
$count = $count + 1;
echo $user[$count];
Upvotes: 0
Reputation: 28076
Use an array. Start with something like:
$users = array(
array('A', 'B'),
array('C', 'D')
);
foreach ($users as $user) {
echo "Username: ".$user[0]. "\n";
echo "Password: ".$user[1]. "\n";
}
Upvotes: 3
Reputation: 485
Var concatenation is not very "recommended", but...
$user = ${'user'.$count}
You should consider using an array instead.
Upvotes: 3