$a = array("val1", "val2", "val3"...);
$s = "str";
echo $result["val1"]["val2"]["val3"]...; // вывод - "str"
function toMultidimensional(array $levels, $value=null) {
$levelsQuantity = count($levels);
$encodedArrayStart = "";
$encodedArrayEnd = "";
foreach ($levels as $i=>$level) {
$encodedArrayStart .= "{\"{$level}\":";
$encodedArrayEnd .= "}";
if ($i==$levelsQuantity-1) {
$encodedArrayStart .= json_encode($value);
}
}
$encodedArray = $encodedArrayStart . $encodedArrayEnd;
$array = json_decode($encodedArray, true);
return $array;
}