如何从给定的URL参数中正确获取和打印值

时间:2014-10-22 12:28:43

标签: php arrays geturl

我有这个链接参数:

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

我希望得到所有的id值,形成一个数组并输出到一个字段,我已经尝试了几种方法,但没有一种方法,任何人都可以帮忙吗?感谢

  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 ;

我希望它会在现场输出:“571,550,276”

1 个答案:

答案 0 :(得分:0)

您的所有参数都将被忽略,它们在您的网址中必须是唯一的 尝试使用此方法http://example.com/article?id=571, 550, 276

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