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