title: replace text in associative array with text from another array
body: <p>I have a array like so</p>
  
  <pre><code>$tags = 
  
  Array
  (
     [0] =&gt; Array
      (
          [0] =&gt; [first_name] [last_name]
          [2] =&gt; [city],[state] [zipcode]
      )
  
   )
  </code></pre>
  
  <p>i also have a list like so</p>
  
  <pre><code>$array_list = 
  
    [0] =&gt; Array
      (
          [first_name] =&gt; Bob
          [last_name] =&gt; Johnson
          [city] =&gt; mycity
          [state] =&gt; NY
          [zipcode] =&gt; 911564
      )
  
  [1] =&gt; Array
      (
          [first_name] =&gt; John
          [last_name] =&gt; Doe
          [city] =&gt; New York
          [state] =&gt; NY
          [zipcode] =&gt; 9115
  
      )
  
  [2] =&gt; Array
      (
          [first_name] =&gt; James
          [last_name] =&gt; Belt
          [city] =&gt; Los Angeles
          [state] =&gt; CA
          [zipcode] =&gt; 915456
      )
  </code></pre>
  
  <p>I basically want to replace all the tags inside of the brackets with the actual value from the array. I tried the following but it only seems to be returning a single value back correctly</p>
  
  <pre><code> foreach($tags as $key=&gt;$value) {
       $data[$key] = preg_replace_callback('/[\[|&lt;](.*)[\]\)]/U', 'replace_text', $value);
   }
  
  
  
   function replace_text($matches) {
      foreach ($array_list as $arg) {
         return $args[$matches[1]];
  
      }        
  
    }
  </code></pre>
  
  <p>Im only getting back one result that looks like so</p>
  
  <pre><code>Array
  (
     [0] =&gt; Array
      (
          [0] =&gt; Bob Johnson
          [1] =&gt; mycity,NY 911564
      )
  
  )
  </code></pre>
  
  <p>how can i do it so that i get all the results back in a array with all the correct values</p>
  
  <p>i tried to change the function replace_text to set the values to a array and return the array like so </p>
  
  <pre><code> function replace_text($matches) {
      foreach ($array_list as $arg) {
         $new_array[]= $args[$matches[1]];
  
      }    
  
       return $new_array;
  
    }
  </code></pre>
  
  <p>but this returns</p>
  
  <pre><code> Array
  (
  [0] =&gt; Array
      (
          [0] =&gt; Array Array
          [1] =&gt; Array
          [2] =&gt; Array,Array Array
      )
  
   )
  </code></pre>
  
  <p>I should also add that all this content is dynamic so one time it may be [first_name] and the next [name_first] or somethign else which is why i need to fine the brackets in each and replace the text inside of brackets with what matches the array.</p>