Search code examples
phparraysgeturl

How to get and print values properly form a given URL parameter


I have this link with parameter:

http://example.com/article?id=571&id=550&id=276

I wish to get all the id values, form an Array and output to a field, I have tried several ways but none worked, anyone can help ? Thanks

  if (isset($_GET['id'])){

      // create an array to store all ids from the parameter

      // Output each values in the array to $string variable

      $form['submitted']['my_field']['#value'] = $string;  // output all ids via this field.

  }; //endif ;

I wish it will output like this on the field: "571, 550, 276"


Solution

  • all of your arguments will be ignored, they must be unique in your URL
    Try With this approach http://example.com/article?id=571, 550, 276

    if(isset($_GET['id'])){
    print $_GET['id'];
    }