Jump to content

a function


runeveryday

Recommended Posts

function url($array) { 
    $gets = $_GET; 
    $gets = array_merge($gets,$array); 
    return '?'.http_build_query($gets); 
} 

 

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

Link to comment
https://forums.phpfreaks.com/topic/213358-a-function/
Share on other sites

The benefit of the array_merge() line of code is it enabled you to pass in an array to the function and that array will be appended to the $gets array, and then converted to a query string (along with the $_GET array).

 

If you removed that line then the function would just return the current query string always, the same as returning $_SERVER['QUERY_STRING']

Link to comment
https://forums.phpfreaks.com/topic/213358-a-function/#findComment-1110861
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.