title: Merging array values depending on what values are set
body: <p>Currently, I am trying to make my URL shortener script able to track UTM variables from Google Analytics. I also want to provide my own (campaign/keyword/source/etc...) variables.</p>
  
  <p>I am trying to sift through $_GET, pick out "approved" key/value pairs and set each key with the condition that UTM variables take higher precedence (I only want to store one value in the database).</p>
  
  <p>My code is currently:</p>
  
  <pre><code>//Parse $_GET and only get the key/pairs that we need and store them in global $url_params for use through out the script
  function set_url_params($allowed=NULL) { // $allowed is arg to add new values in future dev 
  global $url_params;
  
  $allowed = array( 
      'l', // Redirect key (e.g http://example.com?l=a1dFd7)
      'utm_campaign', 
      'campaign', 
      'utm_source' , 
      'source', 
      'utm_medium', 
      'medium', 
      'utm_term', 
      'term', 
      'keyword',
      'kw',
      );
  
      $approved = array_intersect_key($_GET, array_flip($allowed));
  
      foreach($approved as $key =&gt; $value) {
          strip_tags(urldecode(trim($value)));
          $url_params[$key] = $value;
      }
  
      //Assign variables to global $url_params variable so other functions can use them.
      //NOTE: Google Analytics UTM parameters take precedence over script values.
      $url_params['l'] = isset($approved['l']) ? $approved['l'] : NULL ;
      $url_params['campaign'] = isset($approved['utm_campaign']) ? $approved['utm_campaign'] : $approved['campaign'];
      $url_params['source'] = isset($approved['utm_source']) ? $approved['utm_source'] : $approved['source'];
      $url_params['medium'] = isset($approved['utm_medium']) ? $approved['utm_medium'] : $approved['medium'];
      $url_params['term'] = isset($approved['utm_term']) ? $approved['utm_term'] : $approved['term'];
      $url_params['keyword'] = isset($approved['keyword']) ? $approved['keyword'] : $approved['kw'];
      // Just in case $url_params doesn't have a 'keyword' set, we will use 'term' instead.
      $url_params['keyword'] = isset($url_params['keyword']) ? $url_params['keyword'] : $url_params['term'];
  
  }
  </code></pre>
  
  <p>I basically want to find a cleaner way of doing this without all the isset()'s. I also get NOTICE errors (running in E_ALL) for undefined variables that I would like to unset so I don't get those errors.</p>