title: How to grab URL parameters using PHP?
body: <p>I'm trying to grab each URL parameter and display them from first to last, but I want to be able to display any of the parameters anywhere on the page. How can I do this?  What do I have to add or modify on my script?</p>
  
  <p>Here is an example of a URL value.</p>
  
  <pre><code>http://www.localhost.com/topics/index.php?cat=3&amp;sub1=sub-1&amp;sub2=sub-2&amp;sub3=sub-3&amp;sub4=sub-4
  </code></pre>
  
  <p>Here is my PHP script.</p>
  
  <pre><code>$url = $_SERVER['QUERY_STRING'];
  $query = array();
  
  if(!empty($url)){
    foreach(explode('&amp;', $url) as $part){
      list($key, $value) = explode('=', $part, 2);
      $query[$key] = $value;
    }
  }
  </code></pre>