title: Generate URL with parameters from an array
body: <p>I need to take an array like I have below:</p>
  
  <pre><code>$subids = Array
      (
          [s1] =&gt; one
          [s2] =&gt; two
          [s3] =&gt; three
          [s4] =&gt; four
          [s5] =&gt; five
          [s6] =&gt; six
      )
  </code></pre>
  
  <p>and generate a URL such as <a href="http://example.com?s1=one&amp;s2=two&amp;s3=three=&amp;s4=four&amp;s5=five&amp;s6=six" rel="noreferrer">http://example.com?s1=one&amp;s2=two&amp;s3=three=&amp;s4=four&amp;s5=five&amp;s6=six</a></p>
  
  <p>All of the subids are not always defined, so sometimes s3 may not be defined, so it shouldn't be appended to the URL. Additionally, whatever the first subid is, it has to have the ? preceding it instead of the ampersand (&amp;)</p>
  
  <p>So if the array is just:</p>
  
  <pre><code>$subids = Array
      (
          [s2] =&gt; two
          [s6] =&gt; six
      )
  </code></pre>
  
  <p>then the URL needs to be <a href="http://example.com?s2=two&amp;s6=six" rel="noreferrer">http://example.com?s2=two&amp;s6=six</a></p>
  
  <p>I have the following so far:</p>
  
  <p>$url = '<a href="http://example.com" rel="noreferrer">http://example.com</a>'</p>
  
  <pre><code>    foreach ($subids AS $key =&gt; $value) {
          $result[$id]['url'] .= '&amp;' . $key . '=' . $value;
      }
  </code></pre>
  
  <p>However, I'm not sure what the best way would be to append the ? at the beginning of the first key/value pair.</p>
  
  <p>I feel like there's a PHP function to help with this but I'm not finding much. I'm using Codeigniter if there's anything I can use that is provided by CI.</p>