a function.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
everydayrun
Forum Commoner
Posts: 51
Joined: Wed Jan 20, 2010 1:30 am

a function.

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: a function.

Post 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.
Post Reply