How can I make a link that justs adds or changes 1 GET var while maintaining all others?
I have a page that is created using different GET vars.
So it will be like mypage.php?color=red&size=7&brand=some%20brand
So I want to have a link that sets it to page=2 or size=8. Whats the easiest way to have a link do that without reseting all the other vars?
I hope that makes sense, let me know if I need to further explain anything
Short answer: no.
The following code will change the values you desire: var arr = ["one","two","three"]; arr. forEach(function(part, index) { arr[index] = "four"; }); alert(arr);
To change the value of all elements in an array: Use the forEach() method to iterate over the array. The method takes a function that gets invoked with the array element, its index and the array itself. Use the index of the current iteration to change the corresponding array element.
You can parse the url with parse_str to get the values of the url. You can then build a http query by using http_build_query:
$query_arr = $_GET; //or parse_str($_SERVER['QUERY_STRING'], $query_arr)
$query_arr["page"] = 2;
$query_arr["size"] = 8;
$query = http_build_query($query_arr);
EDIT: Sorry I mixed up the two functions ... its parse_str()
of course.
http_build_query
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With