PHP在for内部使用for



有人能帮我用随机或顺序的api列表编码执行数据吗

我有10个数据和3个api列表,我希望代码这样做:

data 1  executed by api 1
data 2  executed by api 2
data 3  executed by api 3
data 4  executed by api 1
data 5  executed by api 2
data 6  executed by api 3
data 7  executed by api 1
data 8  executed by api 2
data 9  executed by api 3
data 10 executed by api 1

我试着这样编码,结果并不像我预期的那样:

if(isset($argv[1])){
$no = 1;
$api = 0;
$total = count(explode("n",file_get_contents($argv[1])));
$listapi = file_get_contents($argv[2]);
$listml = file_get_contents($argv[1]);
$ex = explode("n",$listapi);
$exx = explode("n",$listml);
for ($ee = 0; $ee < count($exx); $ee++) {
for ($api = -1; $api < count($listapi); $api++) {
$send = json_decode($curl->get($ex[$api]."?ee=".$exx[$ee]));
$no++;
echo "OKn";
if ($api % count($ex) == 3) {
$api = -1;
echo "Rollingn";
}
}
}

您需要循环data数组,在循环中的api数组中找到相关项,如底部所示。

foreach ($data as $key=>$item){
echo "data $item executed by api ".$api[$key%count($api)]."n";
}

在演示中检查结果

最新更新