gandrap
gandrap

Reputation: 139

put values in array with get parameter

i have this query in link 10_11&9_12&9_14

i need to create array for db to look like this

[0] => 'and value in (11)'
[1] => 'and value in (12,14)'

so i need for every value that is same until _ (in this example 10_ and 9_) to put values after _

this is my code so far:

$test = $_GET['value'];
    foreach($test as $atr_val)
        {
            list($attribute, $value) = explode("_", $atr_val);
            $selected_attributes[] = $attribute;
            $selected_values[] = $value;

        }

i have now values before _ and after, but i don't know what to do after that

Upvotes: 0

Views: 41

Answers (1)

splash58
splash58

Reputation: 26153

Let your query string looks like www.example.com?file.php?10_11&9_12&9_14

Then use this code. Collect them into array and use implode to output:

$test = $_SERVER["QUERY_STRING"];
$test = explode('&', $test);
foreach($test as $atr_val)
   {
   list($attribute, $value) = explode("_", $atr_val);
   $selected_values[$attribute][] = $value;
   }
 foreach($selected_values as $value) 
   echo "and value in (".implode(',', $value).")".'<br>';

output:

and value in (11)
and value in (12,14)

Upvotes: 1

Related Questions