使用 Array as parent/child 映射从嵌套数组中获取数组值

Get Array value from nested Array with Array as parent/child mapping

假设我有一个这样的数组:

$a = array(
    "foo",
    "bar"
);

$b = array(
    "foo" => array(
        "bar" => 1
    )
);

我想用 $a 得到 $b[$a[0]][$a[1]]

假设 $a 的 1..* 长度和 $b.

的 1..* 水平
$result = $b;
foreach ($a as $index) {
    $result = $result[$index];
}
echo $result;

这应该适合你:

<?php

    //As an example
    $a = array(
        "foo",
        "bar",
        "xy",
        "ab"
    );

    $b = array(
        "foo" => array(
            "bar" => array(
                "xy" => array(
                    "ab" => 14  
                ),
            ),
        )
    );

    $end = $b;
    foreach ($a as $index)
        $end = $end[$index];

    echo $end;

?>

输出:

14