$path = array(
[0]=> 44
[1]=> 34
[2]=> 0
);
$menu[$key]['opened'] = true
$menu[$key]['children'][$key]['opened'] = true
$menu[$key]['children'][$key]['children'][$key]['opened'] = true
function ss(&$arr,$path,$cur = 0){
if(isset($arr[$path[$cur]])){
$arr[$path[$cur]]["active"] = true;
if($cur+1 < count($path))
ss($arr[$path[$cur]]["children"],$path,$cur+1);
}
}
$arr = array (
array (
'name' => '-1 пункт',
'active' => false,
'children'=> array(),
),
array (
'name' => '0 пункт',
'active' => false,
'children'=> array(),
),
array (
'name' => '1 пункт',
'active' => false,
'children'=> array(
array(
'name' => '1.0 пункт',
'active' => false,
'children' => array(),
),
array(
'name' => '1.1 пункт',
'active' => false,
'children' => array(
array(
'name' => '1.1.0 пункт',
'active' => false,
'children' => array(),
),
array(
'name' => '1.1.0 пункт',
'active' => false,
'children' => array(),
)
),
),
array(
'name' => '1.2 пункт',
'active' => false,
'children' => array(),
),
),
),
array (
'name' => '2 пункт',
'active' => false,
'children'=> array(),
),
);
$path = [ 2,1,1 ];
var_dump($arr);//реузльтат до входа
ss($arr,$path);
var_dump($arr);//реузльтат после входа
array(4) {
[0]=>
array(3) {
["name"]=>
string(13) "-1 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
[1]=>
array(3) {
["name"]=>
string(12) "0 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
[2]=>
array(3) {
["name"]=>
string(12) "1 пункт"
["active"]=>
bool(false)
["children"]=>
array(3) {
[0]=>
array(3) {
["name"]=>
string(14) "1.0 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
[1]=>
array(3) {
["name"]=>
string(14) "1.1 пункт"
["active"]=>
bool(false)
["children"]=>
array(2) {
[0]=>
array(3) {
["name"]=>
string(16) "1.1.0 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
[1]=>
array(3) {
["name"]=>
string(16) "1.1.0 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
}
}
[2]=>
array(3) {
["name"]=>
string(14) "1.2 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
}
}
[3]=>
array(3) {
["name"]=>
string(12) "2 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
}
array(4) {
[0]=>
array(3) {
["name"]=>
string(13) "-1 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
[1]=>
array(3) {
["name"]=>
string(12) "0 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
[2]=>
array(3) {
["name"]=>
string(12) "1 пункт"
["active"]=>
bool(true)
["children"]=>
array(3) {
[0]=>
array(3) {
["name"]=>
string(14) "1.0 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
[1]=>
array(3) {
["name"]=>
string(14) "1.1 пункт"
["active"]=>
bool(true)
["children"]=>
array(2) {
[0]=>
array(3) {
["name"]=>
string(16) "1.1.0 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
[1]=>
array(3) {
["name"]=>
string(16) "1.1.0 пункт"
["active"]=>
bool(true)
["children"]=>
array(0) {
}
}
}
}
[2]=>
array(3) {
["name"]=>
string(14) "1.2 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
}
}
[3]=>
array(3) {
["name"]=>
string(12) "2 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
}