Does anyone see something wrong with the following function? ( Edit : no, I donβt think that something is wrong, I just check, as this will be inserted into a very common code path.)
function getNestedVar(&$context, $name) { if (strstr($name, '.') === FALSE) { return $context[$name]; } else { $pieces = explode('.', $name, 2); return getNestedVar($context[$pieces[0]], $pieces[1]); } }
This essentially converts:
$data, "fruits.orange.quantity"
in
$data['fruits']['orange']['quantity']
In context, this is for the form utility that I create in Smarty. I also need a name for the form, so I need a line in the form based on the key and cannot directly access the Smarty variable in Smarty.
source share