title: String Replacements from Values in Assoc Array
body: <p>I'm given a string of HTML with some "tokens" in it.  They are structured like <code>{:TOKEN_NAME:}</code></p>
  
  <p>For instance:</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&gt;
      {:TITLE:}
      {:DESCRIPTION:}
      {:KEYWORDS:}
      {:GOOGLE-VERIFY:}
      {:BING-VERIFY:}
      &lt;link rel="stylesheet" href="/assets/css/base.styles.css?_=&lt;?php echo time(); ?&gt;" type="text/css" /&gt;
      &lt;link rel="stylesheet" href="/assets/css/custom.css?_=&lt;?php echo time(); ?&gt;" type="text/css" /&gt;     
  
      &lt;!--[if lt IE 9]&gt;
          &lt;script type="text/javascript" src="/assets/js/modernizr.min.js"&gt;&lt;/script&gt;
      &lt;![endif]--&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;article data-role="page-wrapper" class="container-fluid"&gt;
          &lt;header class="row-fluid" data-role="page-header"&gt;
              &lt;h1 class="span5 logo pull-right"&gt;&lt;a href="http://www.o7thwebdesign.com"&gt;o7th Web Design&lt;/a&gt;&lt;/h1&gt;
              &lt;nav class="span7"&gt;
                  {:PAGE-CONTENT:}
              &lt;/nav&gt;
          &lt;/header&gt;
          &lt;section class="row-fluid" data-role="page-container"&gt;
  
          &lt;/section&gt;
          &lt;footer class="row-fluid" data-role="page-footer"&gt;
  
          &lt;/footer&gt;
      &lt;/article&gt;
      &lt;script type="text/javascript" src="/assets/js/scripts.js?_=&lt;?php echo time(); ?&gt;"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="/assets/js/custom.js?_=&lt;?php echo time(); ?&gt;"&gt;&lt;/script&gt;
      {:GOOGLE-UA:}
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I am also given an associative array, with the token names, and what they should be replaced with, as such:</p>
  
  <pre><code>    // Populate and pull all global smarttags
      private function PullGlobalSmartTags($values){
          return array(array('Name'=&gt;'{:TITLE:}', 'Replacement'=&gt;'&lt;title&gt;' . $values[0] . '&lt;/title&gt;'),
                       array('Name'=&gt;'{:DESCRIPTION:}', 'Replacement'=&gt;'&lt;meta name="description" content="' . $values[1] . '" /&gt;'),
                       array('Name'=&gt;'{:KEYWORDS:}', 'Replacement'=&gt;($values[22]) ? null : '&lt;meta name="keywords" content="' . $values[2] . '" /&gt;'),
                       array('Name'=&gt;'{:GOOGLE-UA:}', 'Replacement'=&gt;'&lt;script type="text/javascript"&gt;var _gaq = _gaq || [];_gaq.push([\'_setAccount\', \'' . $values[3] . '\']);_gaq.push([\'_trackPageview\']);(function(){var ga = document.createElement(\'script\');ga.type = \'text/javascript\'; ga.async = true;ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);})();&lt;/script&gt;'),
                       array('Name'=&gt;'{:GOOGLE-VERIFY:}', 'Replacement'=&gt;'&lt;meta name="google-site-verification" content="' . $values[4] . '" /&gt;'),
                       array('Name'=&gt;'{:BING-VERIFY:}', 'Replacement'=&gt;'&lt;meta name="msvalidate.01" content="' . $values[5] . '" /&gt;'),
                       array('Name'=&gt;'{:PAGE-CONTENT:}', 'Replacement'=&gt;$values[6]),);
      }           
  </code></pre>
  
  <p>Please assume all values in <code>$values</code> populate, and populate correctly (because they do...)</p>
  
  <p>I know with str_replace, and preg_replace I can simply pass arrays in as my needle, replacement, and haystack, however everything I am seeing only shows non-associative arrays.</p>
  
  <p>My question is, how can I do these replacements?   I know that I could simply loop through the array, and do my replacements one at a time, but is there a way to do this without looping?</p>
  
  <p>This does do the trick:</p>
  
  <pre><code>        for($i=0; $i&lt;$gsCt; ++$i){
              $rettemp = str_replace($GlobalSmartTags[$i]['Name'], $GlobalSmartTags[$i]['Replacement'], $rettemp);
          }
  </code></pre>
  
  <p>however, I do not believe it is the most efficient method to do this.</p>