Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assistance with example #24

Open
kdm122 opened this issue Sep 17, 2013 · 3 comments
Open

Assistance with example #24

kdm122 opened this issue Sep 17, 2013 · 3 comments

Comments

@kdm122
Copy link

kdm122 commented Sep 17, 2013

I've scoured trying to find an example to pull a selected field from an array. I can pull fields based on key name just fine, however having an issue determining how to utilize CFP to pull a value from an array, using PHP.

Any assistance would be greatly appreciated. I've greatly appreciated the library having been made available thus far, thanks guys!

@lpotherat
Copy link
Contributor

Hi,
I think I don't understand what you mean by "pull a value from an array". Maybe I can help you if you can clarify your need to me.

If you can do it based on key name, have you tried to use array_flip, in order to use values as keys in your array ?

@kdm122
Copy link
Author

kdm122 commented Sep 18, 2013

My apologies, I didn't quite explain properly.

I had an array of Entries, and then within each entry a set of definitions, along with another array. It wasn't pretty, and there are likely better ways to go about it, but this was my method of resolution:

$root = $plist->getValue(true);
$entries = $root->get('Entries');
foreach ($entries as $entry) {
  $topalias = $entry->get('versions')->getValue();
  foreach ($topalias as $subvalue) {
    $finalvalue = $subvalue->get('versionAliases')->getValue();
  }
  $versionalias = $finalvalue;
}

The $versionalias having been the entry I was pulling from that second tier array. Again, not pretty, but it worked.

Thanks for the quick response, and if there's a more efficient method, I'd love to hear it. Thanks!

@rodneyrehm
Copy link
Collaborator

As the API stands today, there is not a more efficient approach than the one you chose. In terms of working with $plist that is. One could probably optimize the looping (unless you really want the very last $finalvalue of the very last $entry).

That said, it would be possible to implement an xPath / CSS-selector like approach to navigate within a $plist. Something that would convert your above looping thing into $versionalias = $plist->find('versions:last/versionAliases:last')->getValue();

I'd be happy to merge a PR resolving this ;)

@ajsb85 ajsb85 added this to Backlog in Package Apr 18, 2018
@ajsb85 ajsb85 removed this from Backlog in Package Apr 18, 2018
@ajsb85 ajsb85 added this to To do in Website Apr 18, 2018
@ajsb85 ajsb85 added this to the 3.0 milestone Apr 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Website
  
To do
Development

No branches or pull requests

7 participants