duankeye2342 2013-11-02 21:30
浏览 131
已采纳

php在for循环中调用几个函数

Is it possible to call functions within for loops? I have a number of databases that are exactly the same, I would like to use a for loop to set up the connections one at a time (35 databases). I am having trouble with getting php to declare a function with a variable in the name.

for ($i = 1; $i <= 35; $i++) 
{
    $j=$i+2;
    echo "<br><br>DB $i";
    $connection$j = prodDB$i();
    $getFromDB = "select URL, count(id) as counts from ProductList GROUP BY URL";
    $NamesReturned = mysqli_query($connection$j,$getFromDB) or die("Can't execute query GFNFDB.<br><br>$getFromDB<br><br>");
    while ($ret=mysqli_fetch_array($NamesReturned))
    {
        $DB$icounts=$ret["counts"];
        $URL=$ret["URL"];
        echo "<br>$DB$icounts -- $URL";
    }
    echo "<br>$DB$icounts";
}
  • 写回答

1条回答 默认 最新

  • douzheyo2617 2013-11-02 21:37
    关注

    I think what you need to use is braces. Eg: $connection{$j}=prodDB{$i}();

    I could be wrong though. It has been a long time since i did it.

    You might be better using arrays and/or passing parameters to your functions. Eg:

    $connection[$j]=prodDB($i);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部