Search code examples
phparraysvariablesurlvariables

Single url variable with multiple values into array


I have a url with a single variable (category), but the variable has multiple values.

Example: http://websiteurl.com/?category=cat+dog+rabbit+-cow

I'd like to generate an array with this information.

    <?$category[] = $_GET['category'];?>

print_r reveals this:

    $category = Array ( [0] => cat dog rabbit -cow )

Here's what I need that to look like:

    $category = array('cat','dog','rabbit','-cow');

Solution

  • Have you tried...

    $categories = explode(' ', $_GET['category']);