Thanks for your replies.

I understand the differences between the 2 types of array.
I only asked why when I add another key and end up with array(4=>$a,
12=>$b), NOW the Set::extract is working as normal.

As for the combination of extract and combine, I believe there could
be situations where it's useful.
In my case, I take the result of my find and combine the array in a
way that I can group data of the same type together.
This allow me to do a simple foreach on every type possible (they can
vary) and compute stats for each of them based on their data.
There are surely other ways to do it, but depending on different
factors, this is the quickest and cleanest I've found.

So this result of find
Array
(
    [0] => Array
        (
            [data] => Array
                (
                    [some data] => some value
                    [type] => type1
                )
        )
     ...
)

Become
Array
(
    [type1] => Array
        (
            [4] => Array
                (
                    [data] => Array
                        (
                            [some data] => some value
                            [type] => type1
                        )
                    ...
                )
            [12] ...
        )
    [type2] ...
)

Obviously, this is based on the possibility to do an extract on any
type of array, which is not the case, and that's what led me to my
final question on the combine.

But as I see your last answer, I suppose that it's not possible to
combine with default numeric keys.
I'll do a simple foreach.

On 5 mai, 04:03, "Dr. Loboto" <[email protected]> wrote:
> If you wantextract, do Set::extract(), if you want combine, do
> Set::combine(). I do not see sense in mixing them.
>
> On 4 май, 13:21, Gluckens <[email protected]> wrote:
>
>
>
>
>
>
>
> > This lead me to another question.
>
> > Is it possible to do a combine with default numeric key (0, 1, 2)
>
> > I was doing something like this :
> > $combine = Set::combine($result, '{n}.Data1.id', '{n}',
> > '{n}.Data2.name');
> > which return
> > Array
> > (
> >     [name1] => Array
> >         (
> >             [4] => Array
> >                 (
> >                     [some data] => some value
> >                 )
> >             [12] => Array
> >                 (
> >                     [some data] => some value
> >                 )
> >         )
> > )
>
> > But i'll like to get default numeric key instead of {n}.Data1.id
> > Something like :
> > Array
> > (
> >     [name1] => Array
> >         (
> >             [0] => Array
> >                 (
> >                     [some data] => some values
> >                 )
> >             [1] => Array
> >                 (
> >                     [some data] => some values
> >                 )
> >         )
> > )
>
> > I know that at this point I could simply do a foreach, but it could be
> > useful to know.
> > Thanks in advance.
>
> > On 4 mai, 10:46, Gluckens <[email protected]> wrote:
>
> > > Really?
>
> > > I was doing anextracton a previous combine which put the ID as the
> > > numeric key.
> > > But, switching it with a 0 and now everything seems to work.
>
> > > Still, it's strange that when I add another element with random key,
> > > it's now working.
>
> > > Anyway, I'll find an alternative for my ids.
>
> > > Thanks for the reply.
>
> > > On 4 mai, 08:01, "Dr. Loboto" <[email protected]> wrote:
>
> > > > Set::extract("/Some/thing", $data) assumes that you have true list -
> > > > array with numeric keys 0, 1, 2, ... - but not an associative array
> > > > with keys "some", "thing", ... or 4, 2, 15, ...
>
> > > > If you call it as Set::extract("/Some/thing", array_values($data))
> > > > when $data is associative array it will pass.
>
> > > > On 3 май, 16:21, Gluckens <[email protected]> wrote:
>
> > > > > Of course I know how to do it whithout theextractmethod.
>
> > > > > The point is, if theextractis not always working, it's not really
> > > > > usable cause you never know when it will break your things
>
> > > > > Someone points me to this ticket which could be 
> > > > > relatedhttp://cakephp.lighthouseapp.com/projects/42648/tickets/104-testpatch...
>
> > > > > But anyway, this fix would probably not be coming soon
>
> > > > > Seems like I'll need to rewrite large parts of code... ugh
>
> > > > > On 2 mai, 19:51, Otavio Martins Salomao <[email protected]>
> > > > > wrote:
>
> > > > > > u try this!
> > > > > > foreach($test as $element)
> > > > > >      $result = $element['Deep1']['Deep2']['extract'];
>
> > > > > > 2011/5/2 Gluckens <[email protected]>
>
> > > > > > > Hi everyone,
>
> > > > > > > I'm trying toextractdata from an array containing only one element
> > > > > > > and it doesn't seem to work properly.
> > > > > > > Here's an example :
>
> > > > > > > Starting array
> > > > > > > $test = array(4 => array('Deep1' => array('data1' => 'nothing',
> > > > > > > 'Deep2' => array('extract' => 1))));
> > > > > > > Array
> > > > > > > (
> > > > > > >    [4] => Array
> > > > > > >        (
> > > > > > >            [Deep1] => Array
> > > > > > >                (
> > > > > > >                    [data1] => nothing
> > > > > > >                    [Deep2] => Array
> > > > > > >                        (
> > > > > > >                            [extract] => 1
> > > > > > >                        )
> > > > > > >                )
> > > > > > >        )
> > > > > > > )
>
> > > > > > > Set::extract('/Deep1/Deep2[extract=1]', $test);
> > > > > > > NOT CORRECT
> > > > > > > Array
> > > > > > > (
> > > > > > > )
>
> > > > > > > But, when I add another element, let's say
> > > > > > > $test[12] = array();
> > > > > > > It works fine
> > > > > > > Set::extract('/Deep1/Deep2[extract=1]', $test);
> > > > > > > CORRECT
> > > > > > > Array
> > > > > > > (
> > > > > > >    [0] => Array
> > > > > > >        (
> > > > > > >            [Deep2] => Array
> > > > > > >                (
> > > > > > >                    [extract] => 1
> > > > > > >                )
> > > > > > >        )
> > > > > > > )
>
> > > > > > > Am I using it properly?
> > > > > > > Thanks in advance for any help.
>
> > > > > > > --
> > > > > > > Our newest site for the community: CakePHP Video Tutorials
> > > > > > >http://tv.cakephp.org
> > > > > > > Check out the new CakePHP Questions 
> > > > > > > sitehttp://ask.cakephp.organdhelp
> > > > > > > others with their CakePHP related questions.
>
> > > > > > > To unsubscribe from this group, send email to
> > > > > > > [email protected] For more options, visit 
> > > > > > > this group
> > > > > > > athttp://groups.google.com/group/cake-php

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to