G
G
Grigory Vasilkov2016-06-18 14:41:07
PHP
Grigory Vasilkov, 2016-06-18 14:41:07

How is it more convenient to make grouping with group nesting in PHP?

Yes, in general, it’s not the essence of what language, it’s more interesting to understand the way of thinking, let’s say if I need to do
$obj = new MyClass();
$obj->startGroup();
$obj->action1();
$obj->startGroup();
$obj->action1();
$obj->action2();
$obj->endGroup();
$obj->endGroup();
$obj->startGroup();
$obj->action1();
$obj->endGroup();
a third-party counter and an array of groups suggests itself,
but how then to collect these groups in the correct order later, given that one group may or may not be nested in another.
The essence is to store the specified actions as a list in a specific group.
How it is more convenient to make it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Semenko, 2016-06-18
@abler98

array, right?

$groups = [
    [
        'action1',
        [
            'action1',
            'action2',
        ]
    ],
    [
        'action1',
    ]
];

array_walk_recursive($groups, function ($action) {
    //
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question