This is a continuation to my previous article on how to get values of multi-dimensional arrays using xpath notation.
This time I will show you how to set a value of an array using the same xpath notation (root/branch/leaf).
Sometimes we have a value burried deep within a multi-dimensional array. In order to access it we usually end up doing something like this:
- $value = $array['a']['b']['c'];
hoping that all the keys are set. However, we have a problem if 'b' is not set or any other of the "path" keys are missing.
Wouldn't it be nice if we could get the value using something similar to xpath, e.g. "a/b/c" and specify the default value if the chain is broken? I thought it would and wrote this little function or/and extension to ArrayObject.