Skip to content

Instantly share code, notes, and snippets.

@iammerrick
Created November 16, 2010 23:29
Show Gist options
  • Save iammerrick/702735 to your computer and use it in GitHub Desktop.
Save iammerrick/702735 to your computer and use it in GitHub Desktop.
// Returns "?sort=title&limit=10" combined with any existing GET values
$query = URL::query(array('sort' => 'title', 'limit' => 10));
public static function query(array $params = NULL)
{
if ($params === NULL)
{
// Use only the current parameters
$params = $_GET;
}
else
{
// Merge the current and new parameters
$params = array_merge($_GET, $params);
}
if (empty($params))
{
// No query parameters
return '';
}
$query = http_build_query($params, '', '&');
// Don't prepend '?' to an empty string
return ($query === '') ? '' : '?'.$query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment