Giter Site home page Giter Site logo

Add 'nest' method to ArrayHelper about arrays HOT 6 OPEN

yiisoft avatar yiisoft commented on August 23, 2024
Add 'nest' method to ArrayHelper

from arrays.

Comments (6)

yii-bot avatar yii-bot commented on August 23, 2024

Thank you for putting effort in the improvement of the Yii framework.
We have reviewed your pull request.

Unfortunately a use case is missing. It is required to get a better understanding of the pull request and helps us to determine the necessity and applicability of the suggested change to the framework.

Could you supply us with a use case please? Please be as detailed as possible and show some code!

Thanks!

This is an automated comment, triggered by adding the label pr:missing usecase.

from arrays.

johonunu avatar johonunu commented on August 23, 2024

@samdark

Here are some use cases:

from arrays.

samdark avatar samdark commented on August 23, 2024
  • When you want to generate/print multi-level structure for comments
  • When you want to generate/print multi-level menu

Why aren't you iterating and outputting it right away?

protected function renderComments($parentID = null, $i = 0)
{
    $out = '';
    foreach ($this->comments as $comment) {
        if ($comment->parent_id === $parentID) {
            
            $out .= $this->render('comment', [
                'comment' => $comment, 'class' => $parentID !== null && $i !== 0 ? 'child-comment' : ''
            ]);
            $i++;
            $out .= $this->renderComments($comment->id, $i);
        }
    }
    
    return $out;
}
  • When you want to generate tree (nested set) for use with js plugins

OK, that one makes sense...

from arrays.

samdark avatar samdark commented on August 23, 2024

Is it possible to get same response using ArrayHelper::map somehow ?

No.

from arrays.

SamMousa avatar SamMousa commented on August 23, 2024

@johonunu CakePHP releases their utility classes in a separate package; you could use that.

https://packagist.org/packages/cakephp/utility

from arrays.

johonunu avatar johonunu commented on August 23, 2024

@SamMousa I know that, I just wanted to note that it would be good idea to have it in the core. Most of the methods in Hash class are available inside ArrayHelper, but something like "nest" isn't. I can live without it in core, if I am the only one missing it ;)

from arrays.

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.