UrlHelper.php
public static function buildQuery(array $query, $parent = '') {
    $params = [];

    foreach ($query as $key => $value) {
      $key = ($parent ? $parent . rawurlencode('[' . $key . ']') : rawurlencode($key));

      // Recurse into children.
      if (is_array($value)) {
        $params[] = static::buildQuery($value, $key);
      }
      // If a query parameter value is NULL, only append its key.
      elseif (!isset($value)) {
        $params[] = $key;
      }
      else {
        // For better readability of paths in query strings, we decode slashes.
        $params[] = $key . '=' . str_replace('%2F', '/', rawurlencode($value));
      }
    }

    return implode('&', $params);
  }
public static function buildQuery(array $query, $parent = '') {
    $params = [];

    foreach ($query as $key => $value) {
      $key = ($parent ? $parent . rawurlencode('[' . $key . ']') : rawurlencode($key));

      // Recurse into children.
      if (is_array($value)) {
        $params[] = static::buildQuery($value, $key);
      }
      // If a query parameter value is NULL, only append its key.
      elseif (!isset($value)) {
        $params[] = $key;
      }
      else {
        // For better readability of paths in query strings, we decode slashes.
        $params[] = $key . '=' . str_replace('%2F', '/', rawurlencode($value));
      }
    }

    return implode('&', $params);
  }
public static function buildQuery ( array $ query , $ parent = '' ) { $ params = [ ] ; foreach ( $ query as $ key => $ value ) { $ key = ( $ parent ? $ parent . rawurlencode ( '[' . $ key . ']' ) : rawurlencode ( $ key ) ) ; // Recurse into children. if ( is_array ( $ value ) ) { $ params [ ] = static :: buildQuery ( $ value , $ key ) ; } // If a query parameter value is NULL, only append its key. elseif ( ! isset ( $ value ) ) { $ params [ ] = $ key ; } else { // For better readability of paths in query strings, we decode slashes. $ params [ ] = $ key . '=' . str_replace ( '%2F' , '/' , rawurlencode ( $ value ) ) ; } } return implode ( '&' , $ params ) ; }
Parses an array into a valid, rawurlencoded query string.

rawurlencode() is RFC3986 compliant, and as a consequence RFC3987
compliant. The latter defines the required format of "URLs" in HTML5.
urlencode() is almost the same as rawurlencode(), except that it encodes
spaces as "+" instead of "%20". This makes its result non compliant to
RFC3986 and as a consequence non compliant to RFC3987 and as a consequence
not valid as a "URL" in HTML5.

@todo Remove this function once PHP 5.4 is required as we can use just
http_build_query() directly.

@param array $query
The query parameter array to be processed; for instance,
\Drupal::request()->query->all().
@param string $parent
(optional) Internal use only. Used to build the $query array key for
nested items. Defaults to an empty string.

@return string
A rawurlencoded string which can be used as or appended to the URL query
string.

@ingroup php_wrappers
Parses an array into a valid rawurlencoded query string .