ネストした配列にドットでアクセス+keyがなかったら例外
code:php
<?php
$getOrFail = function (string $key, array $data) {
$keys = explode(".", $key);
$current = $data;
$history = [];
foreach ($keys as $k) {
if (!is_array($current)) {
throw new Exception("type error");
}
$history[] = $k;
$current =
throw new Exception(implode(".", $history) . " is required");
}
return $current;
};