Manipulate a url string by adding GET parameters

前端 未结 15 2140
旧巷少年郎
旧巷少年郎 2020-11-29 00:50

I want to add GET parameters to URLs that may and may not contain GET parameters without repeating ? or &.

Example:

If I want t

15条回答
  •  日久生厌
    2020-11-29 01:08

    $parameters = array();
    
    foreach ($get as $key => $value)
    {
         $parameters[] = $key.'='.$value;
    }
    
    $url = 'http://example.com/movies?'.implode('&', $parameters);
    

提交回复
热议问题