Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7408217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:52:31+00:00 2026-05-29T05:52:31+00:00

My question is simple, but for me, it is creating so many confusions in

  • 0

My question is simple, but for me, it is creating so many confusions in my mind. I want to know that can we input an array to curl function ?

please note that ‘I AM NOT POSTING DATA’ (FOR POSTING DATA , I KNOW, ARRAY IS USED)

To make my question more clear, let me tell you the code ..

function mycurl($url){
$ch = curl_init(); // create a new cURL resource
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$data = curl_exec($ch); // grab URL and pass it to the browser
//echo $data; //ncomment for debugging
curl_close($ch); 
return $data;

}

and array i am going to use is

myArray 
0 => string 'http://www.abc.com/a
1 => string 'http://www.abc.com/b
2 => string 'http://www.abc.com/c
3 => string 'http://www.abc.com/d

to use the array, I am using foreach loop the code is given below

foreach ($myArray as $temp){
    $heading= mycurl($temp);
    echo $heading;
    }

the purpose of the code is

  • go to each url of array using curl function
  • extract required
    data from the url

  • process the next element of array and extract
    data and so on

  • Can anybody guide me that How can i use array elements in curl function?
    How can i get my objective? If foreach loop is not the correct methodology here, then what should I do?

    • 1 1 Answer
    • 0 Views
    • 0 Followers
    • 0
    Share
    • Facebook
    • Report

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    1 Answer

    • Voted
    • Oldest
    • Recent
    • Random
    1. Editorial Team
      Editorial Team
      2026-05-29T05:52:32+00:00Added an answer on May 29, 2026 at 5:52 am

      What your doing looks good, except, you shouldn’t initialize the curl handler for every iteration, just initialize it once, then change the $url value for every iteration, would look something like:

      function mycurl($ch, $url) {
      
          curl_setopt($ch, CURLOPT_URL,$url);
      
          return curl_exec($ch); 
      }
      
      $ch = curl_init(); // create a new cURL resource
      
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
      
      foreach ($urls as $url) {
          $header = mycurl($ch, $url);
          var_dump($header);
      }
      
      curl_close($ch);
      
      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report

    Sidebar

    Related Questions

    this may be a simple question but i can't figure the solution.Im creating a
    This is probably a simple question but I can't seem to find the solution.
    This is probably a simple question but I can't seem to figure out how
    The question is simple, there are many API specific methods in other languages, but
    I'm creating small engine/framework for making games. It's kind of simple question but I
    Simple question but I got a headache to solve this game. Example regex. [a-zA-Z0-9\s]
    Simple question but i need it :) $query = SELECT * FROM `set` WHERE
    Simple question but cannot find answer anywhere. When using a MS Chart Control of
    Sorry for the simple question but I feel like there's a smarter way to
    This is probably a simple question but I am not an ASP.NET developer and

    Explore

    • Home
    • Add group
    • Groups page
    • Communities
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Polls
    • Tags
    • Badges
    • Users
    • Help
    • SEARCH

    Footer

    © 2021 The Archive Base. All Rights Reserved
    With Love by The Archive Base

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.