Answer the question
In order to leave comments, you need to log in
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
array, right?
$groups = [
[
'action1',
[
'action1',
'action2',
]
],
[
'action1',
]
];
array_walk_recursive($groups, function ($action) {
//
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question