How can I programmatically create a link/URL with querystrings set from parameters? In Drupal 8 I customize the filter in the block in the sidebar menu. When the user clicks on the option in the block, I need to pass his choice to the URL. 

$this-&gt;args = \Drupal::request()-&gt;query-&gt;all();
$args[$id] = $value;
$url = $this-&gt;url = Url::fromRoute('&lt;current&gt;');
$url-&gt;setOptions(array('query' =&gt; $args));
$link = '&lt;a href="' . $url-&gt;toString() . '"&gt;' . $label . '&lt;/a&gt;';


And in the end, my URL looks like 

 drupal/page_view?content_type=type


but I need my URL to look like 

drupal/page_view?content_type%5Btype%5D=type


Do you know how can I modify my code?
Let's say if your $args is an array like below:

$args['content_type'] = 'type';


Then you have to append type to it rather than just giving your $id to $args

$args['content_type'] = ['type' =&gt; '123'];


Then your overall query will be like:

$this-&gt;args = \Drupal::request()-&gt;query-&gt;all();
$this-&gt;args = [$id =&gt; $value];
$url = $this-&gt;url = Url::fromRoute('&lt;current&gt;');
$url-&gt;setOptions(array('query' =&gt; $args));
$link = '&lt;a href="' . $url-&gt;toString() . '"&gt;' . $label . '&lt;/a&gt;';