title: Parsing closed brackets in URL and http_build_query with it inserts number in closed bracket
body: <p>may not have explained this properly but here we go.</p>
  
  <p>I have a URL that looks like <a href="http://www.test.co.uk/?page=2&amp;area[]=thing&amp;area[]=thing2" rel="nofollow">http://www.test.co.uk/?page=2&amp;area[]=thing&amp;area[]=thing2</a></p>
  
  <p>Multiple "area"s can be added or removed from the URL via links on the site. on each addition of n "area" I wanted to remove the "page" part of the URL. so it can be reset to page1. I used parse_url to take that bit out.</p>
  
  <p>Then I built an http query so it could generate the URL properly without "page"</p>
  
  <p>this resulted in "area%5B0%5D=" "area%5B1%5D=" instead of "area[]="</p>
  
  <p>When I use urldecode, now it shows "area[0]=" and "area[1]="</p>
  
  <p>I need it to be "[]" because when using a link to remove an area, it checks for the "[]=" - when it's [0] it doesn't recognise it. How do I keep it as "[]="?</p>
  
  <p>See code below.</p>
  
  <pre><code>  $currentURL = currentURL();
  
      $parts = parse_url($currentURL);
     parse_str($parts['query'], $query);
     unset($query['page']);
     $currenturlfinal = http_build_query($query);
   urldecode($currenturlfinal);
    $currentURL = "?" . urldecode($currenturlfinal);
  </code></pre>
  
  <p>This is what I've done so far - it fixes the visual part in the URL - however I don't think I've solved anything as I've realised that what represents 'area' and 'thing' is not recognised as $key or $val as a result of what I think is parsing or reencoding the url in accordance with the code below. So I still can't remove 'areas' using the links</p>
  
  <pre><code>  $currentURL_with_QS2 = currentURL();
  
     $parts = parse_url($currentURL_with_QS2);
     parse_str($parts['query'], $query);
     unset($query['page']);
     $currenturlfinal = http_build_query($query);
  
     $currenturlfinal = preg_replace('/%5B[0-9]+%5D/simU', '[]', $currenturlfinal);
     urldecode($currenturlfinal);
  
     $currentURL_with_QS = "?" . $currenturlfinal;
  
  
     $numQueries = count(explode('&amp;', $_SERVER['QUERY_STRING']));
  
     $get = $_GET;
  
  
  
      if (activeCat($val)) { // if this category is already set
  
          $searchString = $key . '[]= ' . $val; // we build the query string to remove
  </code></pre>
  
  <p>I'm using Wordpress as well may I add - maybe there's a way to reset the pagination through Wordpress. of course even then - when I go to page 2 on any page it still changes the "[]" to "5b0%5d" etc....</p>
  
  <p>EDIT: this is all part of a function that refers to $key (the area/category) and $val (name of area or category) which is echoed in the link itself</p>
  
  <p>EDIT2: It works now!<br>
  I don't know why but I had to use the original code and make the adjustments I did before again and now it works exactly how I want it to! Yet I couldn't see any visible differences in both codes afterwards. Strange...</p>