PHP cURL command inside foreach loop only shows last result -
i'm new programming, , i've made page using php lets enter userids , add observers using canvas api , worked great. i'm trying enter list of people observed , have process multiple urls , i'm running problems. seems process final userid in box.
any ideas i'm doing wrong? doesn't need run , i'm not worried performance don't need curl commands process simultaneously.
$observeea = explode ("\n", $observee); $ch = curl_init(); curl_setopt($ch, curlopt_httpheader, $headers); curl_setopt($ch, curlopt_customrequest, "put"); curl_setopt($ch, curlopt_returntransfer, 1); foreach ($observeea $ob2){ if ($idtype == "canvas") { $url = $domain . "/api/v1/users/$observer/observees/" . $ob2; } else { $url = $domain . "/api/v1/users/sis_user_id:$observer/observees/sis_user_id:" . $ob2; } curl_setopt($ch, curlopt_url, $url); $resp = curl_exec($ch); echo $ob2 . "<br>" . $url . "<br>" . $resp . "<br>"; } curl_close($ch); the echo on line 13 outputs correct entries url, never gets response until last 1 in list.
it turns out storing string array explode function included hidden return characters, added $ob2 = trim($ob2); foreach loop , works.
Comments
Post a Comment