Skip to content

Instantly share code, notes, and snippets.

@periplox
Last active December 4, 2018 20:47
Show Gist options
  • Select an option

  • Save periplox/c581513259bc84f1c91e5011c5a26a68 to your computer and use it in GitHub Desktop.

Select an option

Save periplox/c581513259bc84f1c91e5011c5a26a68 to your computer and use it in GitHub Desktop.
Simple function to update query strings. It adds new parameters, updates existing ones and return the updated string.
<?php
function updateQueryString($oldQuery, $newQuery) {
// Parse old string into array
parse_str($oldQuery, $oldParams);
// Parse new string into array
parse_str($newQuery, $newParams);
// Merge both arrays recursivley
$merged = array_replace_recursive($oldParams, $newParams);
//Return the result parsed into a query string
return http_build_query($merged);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment