Question

I have this page set up that logs into a site for me and downloads fresh content to my server. I would like it to do this for a number of accounts, continuing to do so indefinitely as long as my browser has the page open.

In the script, I create the connection like this:$connection = new Connection('myusername','pass');

That said, I would like to take my creds out, and then place variables there. above that I would like to declare an array of username/password combos, but I dont know how to access the indexes. The array would be similar to this:

<?php
$accounts = array(
"foo" => "bar",
"bar" => "foo!",
"foo" => "foo"
"bar" => "bar"
//100   => -100,
//-100  => 100,
);
//var_dump($array);
?>

And so the loop should be something like

<?php
for ($i=0; $i<=count($accounts); $i++) {
//set the first value to username, *****
//set the second value to password *****
//create my connection based on these variables
//do the rest of my steps
}
?> 

The lines with the asterisks are the lines I am unsure of. With the array above, are the elements stored as $accounts[0][0] == 'foo', $accounts[0][0] == 'bar' ?

Suggestions?

Was it helpful?

Solution

In this case, a foreach loop seems more appropriate (and easier):

foreach ($accounts as $username => $password) {
    $connection = new Connection($username, $password);
    // Further processing...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top