表題のようにfor文の中に関数があり、その中で$iを使いたいです。
やりたいことは、結果を順に配列にセットするというもので、求めるreturnも合わせて記載しております。
よろしくお願い致します。
php
1class TestController extends Controller 2{ 3 } 4 public function index() 5 { 6 $client = new Client(); 7 $guzzleClient = new GuzzleClient(array( 8 'timeout' => 120, 9 )); 10 $client->setClient($guzzleClient); 11 12 $baseUrl = "https://hoge.com/fuga.php?id="; 13 $params = $this->queryParams->data(); 14 15 for ($i=0; $i < 10; $i++) { 16 $formattedUrl[$i] = $baseUrl.$params[$i]; 17 $crawler[$i] = $client->request('GET', $formattedUrl[$i]); 18 19 // Get Data Source 20 $crawler[$i]->filter("#tile ul li")->each(function ($node) { 21 $characterArray[$i] = $node->text() . "<br>"; // ←ここの「$i」 22 sleep(5); 23 }); 24 } 25 }
php
1//return 2 3[ 4 0 => hoge huga, 5 1 => hoga huge faga, 6 2 => ... 7 . 8 . 9 9 => ... 10] 11
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/27 02:54