0

I am using the answer here https://stackoverflow.com/a/27689796/3842368 to strip off several parameters from a url. I thought it was working, until today when I found out that unset() wasn't working if I defined multiple parameters.

My PHP code is:

$url = $_SERVER["REQUEST_URI"];
$x = $url;
$parsed = parse_url($x);
$query = $parsed['query'];
parse_str($query, $params);
unset($params['qdef, qval1']);
$string = http_build_query($params);

$params is producing the following array, using print_r:

Array ( [use_url] => on [zipcode] => Axminster, Devon EX13 5RZ [categories] => Array ( [0] => 2 ) [radius] => 0 [checkboxnational] => 1 [submit] => loading results... [yesq] => y [qdef] => 2 [qval1] => 100.00 [qval2] => 525.00 [seasoning] => 1 [slider-value1] => 0 [slider-value2] => 70 [resultbar] => 25 [sortbar] => distance [lat] => 50.77643440000001 [lng] => -2.9810417 [swlat] => 50.7773526197085 [swlng] => -2.9814507999999478 [nelat] => 50.7800505802915 [nelng] => -2.9749947000000247 [outcode] => EX13 ) 1

so the problem I have is that if I write unset($params['qdef']); then qdef is stripped from the url, but if I write unset($params['qdef, qval1']); then nothing is stripped. I've tried separating them with a comma, enclosing each parameter in '[]', nothing works. I've tried many ways of defining the parameters in the unset() command but nothing works.

Any thoughts?

7
  • 2
    unset($params['qdef'], $params['qval1']); Commented Mar 10, 2015 at 0:01
  • unset($params['qdef'], $params['qval1']);? Commented Mar 10, 2015 at 0:01
  • @MarkBaker - You were a bit faster than me =) Commented Mar 10, 2015 at 0:01
  • 1
    @luke_mclachlan - Remember to read the documentation. Commented Mar 10, 2015 at 0:02
  • 1
    Public idiocy is nature's way of teaching us not to make the same mistake a second time ;) Commented Mar 10, 2015 at 0:03

1 Answer 1

1

$params['qdef'] and $params['qval1'] are separate elements in the array

use

unset($params['qdef'], $params['qval1']);

to unset them individually

unset($params['qdef, qval1']); 

is trying to unset a single element from $params with a key of 'qdef, qval1'

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.