doulu8847 2014-04-26 03:19
浏览 40
已采纳

php迭代数组以获取帐户数据

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?

  • 写回答

1条回答 默认 最新

  • du0173 2014-04-26 03:21
    关注

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

    foreach ($accounts as $username => $password) {
        $connection = new Connection($username, $password);
        // Further processing...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)