Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do i loop through an $_GET array and display all variables except the current value. I have a search page that work with $_GET to filter. What i want to do is add buttons to exclude form the next search the current array value but still pass all the other values for example:

<h4>Filters Applied</h4> (click X to remove filters) 
foreach($_GET as $key => $value)
{
echo '<a href="binx/search_advanced.php?'. DISPLAY ALL EXCEPT CURRENT .'"> X - ' . $key . '</a>';
}


I am rather new to PHP so unsure if this is possible and how to achieve it if it is.

What I have tried:

I have tried searching on google but cant seem to find and answer that works in my case.
Posted
Updated 3-Dec-20 6:31am
Comments
Richard MacCutchan 3-Dec-20 12:27pm    
"display all variables except the current value"
How do you decide what is the current value?

1 solution

It's pretty easy logic:

You need to know what you want to exclude.

- If it's an associative array, use a foreach() loop and when you find the match to the one you're wanting to exclude simply skip it and continue the loop.
- If it's an indexed loop (i.e., integers), you can do the same and, if order's important, you can use a for() loop and skip the index(s) you wish;

So: loop, test, act on item or continue.   Testing the members of an array is very basic.

Now - as for "searching google" for an answer that works in your case, you should be trying to learn to code - not copy. You'll


 
Share this answer
 
v2
Comments
Member 15011116 3-Dec-20 13:01pm    
What needs to happen is this should give me a link to exclude the current variable in the array. While looping through the array, so i need a loop inside of a loop ?

Let`s say I have an array to search for A, B, C, D. the link I need is to exclude each on their own to widen the search parameters all 4 should exclude the current value but keep the remainder:

so
link A will include parameters from the array B, C, D
link B will include parameters from the array A, C, D
link C will include parameters from the array A, B, D
link D will include parameters from the array A, B, C

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900