2011-12-12 47 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