title: How can I get only named captures from preg_match?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3275963/how-to-force-preg-match-preg-match-all-to-return-only-named-parts-of-regex-expre">how to force preg_match preg_match_all to return only named parts of regex expression</a>  </p>
  </blockquote>
  
  
  
  <p>I have this snippet:</p>
  
  <pre><code>$string = 'Hello, my name is Linda. I like Pepsi.';
  $regex = '/name is (?&lt;name&gt;[^.]+)\..*?like (?&lt;likes&gt;[^.]+)/';
  
  preg_match($regex, $string, $matches);
  
  print_r($matches);
  </code></pre>
  
  <p>This prints:</p>
  
  <pre><code>Array
  (
      [0] =&gt; name is Linda. I like Pepsi
      [name] =&gt; Linda
      [1] =&gt; Linda
      [likes] =&gt; Pepsi
      [2] =&gt; Pepsi
  )
  </code></pre>
  
  <p>How can I get it to return just:</p>
  
  <pre><code>Array
  (
      [name] =&gt; Linda
      [likes] =&gt; Pepsi
  )
  </code></pre>
  
  <p>Without resorting to filtering of the result array:</p>
  
  <pre><code>foreach ($matches as $key =&gt; $value) {
      if (is_int($key)) 
          unset($matches[$key]);
  }
  </code></pre>