Giter Site home page Giter Site logo

Assistance with example about cfpropertylist HOT 3 OPEN

teclib avatar teclib commented on May 24, 2024 1
Assistance with example

from cfpropertylist.

Comments (3)

lpotherat avatar lpotherat commented on May 24, 2024 1

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 ?

from cfpropertylist.

kdm122 avatar kdm122 commented on May 24, 2024 1

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!

from cfpropertylist.

rodneyrehm avatar rodneyrehm commented on May 24, 2024 1

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 ;)

from cfpropertylist.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.