有人看到以下函数有问题吗?(编辑:不,我认为没有任何问题,我只是再次检查,因为这将被插入到非常常见的代码路径中。)
这将基本上转换为:
function getNestedVar(&$context, $name) {
if (strstr($name, '.') === FALSE) {
return $context[$name];
} else {
$pieces = explode('.', $name, 2);
return getNestedVar($context[$pieces[0]], $pieces[1]);
}
}
这将基本上转换为:
$data, "fruits.orange.quantity"
into:
$data['fruits']['orange']['quantity']
为了更好地理解,我正在构建一个Smarty表单工具。我需要表单的名称,因此字符串必须以键值形式存在,并且不能直接在Smarty中访问Smarty变量。