Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8992603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:59:38+00:00 2026-06-15T22:59:38+00:00

array( [0]=> [index1]=>something [index2]=>something else [index3]=>something more [1]=> [index1]=>something [index2]=>something else [index3]=>something more [2]=>

  • 0
array(
    [0]=>
        [index1]=>something
        [index2]=>something else
        [index3]=>something more
    [1]=>
        [index1]=>something
        [index2]=>something else
        [index3]=>something more
    [2]=>
        [index1]=>something
        [index2]=>something else
        [index3]=>something more
)

EDIT:
So I would like to retrieve the following:

array(
    [0]=>
        [index1]=>something
        [index2]=>something else
    [1]=>
        [index1]=>something
        [index2]=>something else
    [2]=>
        [index1]=>something
        [index2]=>something else
)

How do I get multiple indexes of the array using the Set::extract function in cakephp?

This retrieves one value:

Set::extract($array, '{n}.index1');

but I would like to get multiple values … say, index1 and index2.

I tried statements like the following, to no avail.

Set::extract($array, '[{n}.index1, {n}.index2']);

EDIT

    $__pages = Hash::merge(
                    Hash::extract($pages, 'pages.{n}.id'),
                    Hash::extract($pages, 'pages.{n}.title')
                    );
    pr($__pages);

Output:

Array
(
    [0] => 2
    [1] => 4
    [2] => 104
    [3] => Sample Page
    [4] => about us
    [5] => Services
)

That doesn’t really help me since I still need the association like so:

Array(
   [2] => Sample Page
   [4] => About us
   [104] => Services
)

I would even be happy with :

Array(
   Array(id => 2, title => Sample Page)
   Array(id => 4, title => About Us)
   Array(id => 104, title => Services)
)

ANSWER
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 id, title.

array(
   posts=>
      0=>
         id => 3
         slug => sample-page
         type => page
         title => Sample Page
         //...and so on 

      1=>
         id => 7
         slug => sample-page-2
         type => page
         title => Sample Page 2
         //...and so on 

To retrieve just the id and title I added the following line.

pr(Set::classicExtract($pages, 'pages.{n}.{(id|title)}'));

this gave me:

array(
   posts=>
      0=>
         id => 3
         title => Sample Page

      1=>
         id => 7
         title => Sample Page 2

DOCUMENTATION: Book

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:59:40+00:00Added an answer on June 15, 2026 at 10:59 pm
    $arr = array(
                array(
                    'index1'=>'something',
                    'index2'=>'something else',
                    'index3'=>'something more',
                ),
                array(
                    'index1'=>'something',
                    'index2'=>'something else',
                    'index3'=>'something more',
                ),
                array(
                    'index1'=>'something',
                    'index2'=>'something else',
                    'index3'=>'something more',
                )
            );
    
    $output = Set::classicExtract($arr, '{n}.{index[1-2]}');
    
    print_r($output);
    
    // output
    
    
    Array
    (
        [0] => Array
            (
                [index1] => something
                [index2] => something else
            )
    
        [1] => Array
            (
                [index1] => something
                [index2] => something else
            )
    
        [2] => Array
            (
                [index1] => something
                [index2] => something else
            )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having an array like fallowing, NSArray*array = [NSArray arrayWithObjects:@1.1 something, @1.2 something
I was asked to write something that would determine if an array is a
Am I doing something wrong with the following code? I can't seem to get
Is there a simple way to get array of all index paths for the
I was trying something else but suddenly stuck with this infinite loop . Please
if( (A) && (B) ) { //do something } else //do something else The
How Create multiple array from an array and concatenate each elments? I have an
I have an index view of a model which I would like to filter
Has C# indexed control arrays or not? I would like to put a button
I have a 3D multi_array and I would like to make 2D slices using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.