Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

plucking object properties #34

Open
yankeeinlondon opened this issue May 21, 2014 · 1 comment
Open

plucking object properties #34

yankeeinlondon opened this issue May 21, 2014 · 1 comment

Comments

@yankeeinlondon
Copy link
Contributor

I have a common data structure that looks like:

[
    {"id":"object1", "name": "foo"},
    {"id":"object2", "name": "bar"},
    {"id":"object3", "name": "baz"}
]

I would have thought that by typing:

 echo json_encode( Arrays::pluck($myArray,'name') );

I would get a response of ["foo","bar","baz"]. The result does seem to work in a simple scenario but if I precede this call with a call to Arrays::find($myArray, function () {...}) then the results of the subsequent pluck() produce inconsistent results.

I don't fully understand this inconsistency yet -- although I'm guessing it may come from a false assumption about where the array pointer is starting -- in any event and for what it's worth here is the resultset I get from pluck after the find operation:

["bar","bar","baz"]
@mcordingley
Copy link
Contributor

I'm curious. If you stick a call to reset($myArray) between the call to Arrays":find and Arrays::pluck, does it work again?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants