Page 1 of 1

a function.

Posted: Tue Sep 14, 2010 1:35 am
by everydayrun

Code: Select all

function url($array) { 
    $gets = $_GET; 
    $gets = array_merge($gets,$array); 
    return '?'.http_build_query($gets); 
} 
can't catch up with the above code. hope someone can give me more explaination. as i know, the first line is give the GET array to a variable named $gets. then merge the array. and return the query string. i don't know why i shoud do this line ($gets = array_merge($gets,$array); ).thank you.

Re: a function.

Posted: Tue Sep 14, 2010 1:48 am
by requinix
The point of that function is to take the current query string (the bit after the ? in the URL), add some stuff to it, and return the combined string. array_merge is to combine (a) the current query string and (b) the stuff.
When PHP makes $_GET for you, it looks at the URL, does some work with it, and gets an array. http_build_query does the exact reverse.

See also: the online manual. Because that, and a little bit of thinking for yourself, can answer a lot of questions you might have.