わからないこと
- PHPの処理を関数化したら元々の処理が動かなくなった。
- そもそも関数化できていないのかも知れないです。
関数化したコード
php
1 function getData($id) { 2 $apiUrl = "https://example.com"; 3 $context = stream_context_create( 4 array( 5 'http' => array( 6 'ignore_errors' => true 7 ) 8 ) 9 ); 10 $response = file_get_contents($apiUrl . $id, false, $context); 11 $json = json_decode($response); 12 $name = $json->Name; 13 $prefName = $json->PrefName; 14 $areaName = $json->AreaName; 15 $latitude = $json->Latitude; 16 $longitude = $json->Longitude; 17}
foreach文
php
1foreach ($ids as $id) { 2 $testId = $id->meta_value; 3 getData($testId); 4 // 以下省略 5}
回答1件
あなたの回答
tips
プレビュー