Skip to content
Advertisement

Removing an associated key/value pair from array (nested)

I have two function to add remove parameters to the query string. The “add_query_params” (thanks to this forum) is working nicely and I can now add multiple tags to the query string of the same type.

For example

JavaScript

As you can see, I can add multiple of the same parameters, I am also querying these nicely using queryfilters.

However my newest problem, is simply removing a single tag type without affecting the rest of the query string. I will then rebuild the query without the deleted tag.

Someone kindly yesterday helped me to to a point but this removes ALL tag key values, not just the specified tag.

So if I was to delete say $tags[]shrubs from the above URL it would actually delete BOTH tag[]shrubs AND $tags[]flowers.

This obviously isn’t very intuitive for a filter system I am devising. What I would like to know is how to remove just the single key value pair and leave the other keys pairs intact.

Here is my helper function

JavaScript

This does not work, if I change $value to $key then it will will, but it will remove all keys of the same type, not the behaviour I would like.

I activate this behaviour via a call in the blade template, this forms a href

JavaScript

Has anybody got any pointers as to where I go next?#

Thanks and fingers crossed I am not far off 🙂

Adam

Advertisement

Answer

Hope this will solve your problem.I just provided the core function to get the things done in a way

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement