2011-12-12 46 views
1

我写了一个多重卷曲,它输出两个不同的阵列多个cURL并输出JSON?

我正在使用curl_multi_getcontent。

for($i = 0; $i < $node_count; $i++) 
    { 

     $results = curl_multi_getcontent ($curl_arr[$i] ); 
     $results = json_decode($results,true); 

     /*echo "<pre>"; 
     print_r($results); 
     echo "</pre>";*/ 
    } 

这将输出两个数组。如果我想从一个数组中获取数据,我该如何调用第一个数组?或第二个数组?

有什么样的结果$ [0]或东西第一阵列

foreach($results[0] as $result){ 
    echo $result['pagination']; 
} 

回答

1

是的,截至目前,$ result变量是通过for循环相互覆盖的。试试这个:

for($i = 0; $i < $node_count; $i++) 
{ 
    $results[$i] = curl_multi_getcontent ($curl_arr[$i] ); 
    $results[$i] = json_decode($results,true); 
} 

print_r($results); 

您现在应该有你的数组中的两个元素,你可以通过$results[0]$results[1]等打电话......

+0

这并不表明JSON字符串,它只是 '阵列 { [0] => [1] => }'和孤单那些 – hellomello

+0

没有价值,你在'$ curl_arr有什么数据数组? – dchrastil

+0

我没有改变任何关于你的卷曲对象,所以它应该有相同的阵列,你说它在你的原始文章中打印出来。如果你包含更多的代码,这将有所帮助。 – dchrastil

0

PHP的文档具有使用curl_multi_exec一个例子。基本上,它创建两个cURL句柄,将它们添加到curl_multi_add_handle接口,然后并行运行它们。

+0

如果我使用curl_multi_getcontent能够输出的结果了,我怎么申请来自不同数组的值?我可以输出1个数组和另一个数组,调用这两个数组的最佳方式是什么? – hellomello