Last active
December 4, 2018 20:47
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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