title: Retrieve multiple array values with extract
body: <pre><code>array(
      [0]=&gt;
          [index1]=&gt;something
          [index2]=&gt;something else
          [index3]=&gt;something more
      [1]=&gt;
          [index1]=&gt;something
          [index2]=&gt;something else
          [index3]=&gt;something more
      [2]=&gt;
          [index1]=&gt;something
          [index2]=&gt;something else
          [index3]=&gt;something more
  )
  </code></pre>
  
  <p>EDIT:
  So I would like to retrieve the following:</p>
  
  <pre><code>array(
      [0]=&gt;
          [index1]=&gt;something
          [index2]=&gt;something else
      [1]=&gt;
          [index1]=&gt;something
          [index2]=&gt;something else
      [2]=&gt;
          [index1]=&gt;something
          [index2]=&gt;something else
  )
  </code></pre>
  
  <p>How do I get multiple indexes of the array using the Set::extract function in cakephp?</p>
  
  <p>This retrieves one value:</p>
  
  <pre><code>Set::extract($array, '{n}.index1');
  </code></pre>
  
  <p>but I would like to get multiple values ... say, index1 and index2.</p>
  
  <p>I tried statements like the following, to no avail.</p>
  
  <pre><code>Set::extract($array, '[{n}.index1, {n}.index2']);
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>    $__pages = Hash::merge(
                      Hash::extract($pages, 'pages.{n}.id'),
                      Hash::extract($pages, 'pages.{n}.title')
                      );
      pr($__pages);
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Array
  (
      [0] =&gt; 2
      [1] =&gt; 4
      [2] =&gt; 104
      [3] =&gt; Sample Page
      [4] =&gt; about us
      [5] =&gt; Services
  )
  </code></pre>
  
  <p>That doesn't really help me since I still need the association like so:</p>
  
  <pre><code>Array(
     [2] =&gt; Sample Page
     [4] =&gt; About us
     [104] =&gt; Services
  )
  </code></pre>
  
  <p>I would even be happy with :</p>
  
  <pre><code>Array(
     Array(id =&gt; 2, title =&gt; Sample Page)
     Array(id =&gt; 4, title =&gt; About Us)
     Array(id =&gt; 104, title =&gt; Services)
  )
  </code></pre>
  
  <p><strong>ANSWER</strong>
  thecodeparadox's answer works for the test code that I provided. Here is the real life code in case someone stumbles here.
  In the book it states, "any string literal enclosed in brackets besides {n} and {s}) is interpreted as a regular expression."
  This line seemed to be hidden and not very blatant. So knowing this, I simply used regex rules to retrieve the data I needed. I have an array that pulled wordpress posts from an api, I needed to narrow down the results to <code>id, title</code>.</p>
  
  <pre><code>array(
     posts=&gt;
        0=&gt;
           id =&gt; 3
           slug =&gt; sample-page
           type =&gt; page
           title =&gt; Sample Page
           //...and so on 
  
        1=&gt;
           id =&gt; 7
           slug =&gt; sample-page-2
           type =&gt; page
           title =&gt; Sample Page 2
           //...and so on 
  </code></pre>
  
  <p>To retrieve just the id and title I added the following line.</p>
  
  <pre><code>pr(Set::classicExtract($pages, 'pages.{n}.{(id|title)}'));
  </code></pre>
  
  <p>this gave me:</p>
  
  <pre><code>array(
     posts=&gt;
        0=&gt;
           id =&gt; 3
           title =&gt; Sample Page
  
        1=&gt;
           id =&gt; 7
           title =&gt; Sample Page 2
  </code></pre>
  
  <p>DOCUMENTATION: <a href="http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::extract" rel="noreferrer" title="Book">Book</a></p>