views:

73

answers:

2
+3  A: 
 colors[]=red&colors[]=blue&colors[]=green 

Would be a the Way a Form would submit the data (when method="get"). And you can access it via $_GET['colors'] which is the native and by that probably the fastest way.

EDIT: to get that string via http_build_query just fill them in the array color

$data = array('colors' => array('green','red','blue'));
echo http_build_query($data); // colors[0]=green&colors[1]=red&colors[2]=blue
Hannes
+1: Not to mention that it doesn't require JavaScript to assemble. And it's the most portable method (since all browsers should be able to handle it)...
ircmaxell
@ircmaxell thx - clear case of KISS
Hannes
RS7
@RS7 i have extended my Answer, i hope it helps :)
Hannes
I appreciate everybody's help so far ;) I'm having a hard time making a system to quickly/easily remove parts of an array before outputting the query strings again. I'm new to all of this but is there a function that finds values and deletes that array entry? I know I can do unset($array['key']) but what about values? Sorry - I'm quite new to all of this.
RS7
I've edited the main question with something I've found.
RS7
A: 

Personally I like to reduce the GET vars as much as possible -

$vars = base64_encode(serialize($_POST));
$url = "http://www.somedomain.com/search/".$vars."/search-term";
header('location: '.$url);
    exit;

// this would output something like 
// http://www.somedomain.com/search/YXdlc29tZQ==/search-term/

Then just reverse it on page load and do what you must with the vars:

$uri = explode("/", $_SERVER['REQUEST_URI']);
$vars = unserialize(base64_decode($uri[2]));
// do whatever processing you need to with the vars

This method is good for evaluating top searches and adding to sitemaps, preventing that notice all browsers give if you click refresh and it asks if you want to re-submit the form, etc. Plus, it keeps a semi-readable URL for linking elsewhere if you cared to link search results, and is generally more clean looking.

Notice I appended a slug of the base term at the end too. That's because I do log the searches and add the top 1% to sitemap as "popular"

** UPDATE ** Really? -1? Using checkboxes and serializing $_POST would automatically remove keys from your post array since checkboxes that are not checked do not pass a value. That's the point of my answer which is used professionally on a number of sites with excellent load times. Have I misunderstood your needs, or are you using an unconventional search interface?

This is a site which uses this method in action. It has some 20 options and filters as I assume you are requesting. http://www.lauragibson.com/products/

Not what you need?

Kai Qing