This class allows arbitrary data structures to be inserted into, and extracted from, deep arrays and JSON-serialized strings. Say, for example, that you have this array as an input:
['foo' => ['bar' => ['baz' => 'some_value']]]
and you wanted to insert or extract an element. Usually, you would use:
$array['foo']['bar']['baz'] = 'new_value';
but sometimes you do not have access to the variable - so a string representation is needed. Using XPath-like syntax, this class allows you to do this:
$jsonPath = new JsonPath($array); $jsonPath->set('foo.bar.baz', 'new_value'); $val = $jsonPath->get('foo.bar.baz');
Set a node in the structure
Return the updated structure.
Get a path's value. If no path can be matched, NULL is returned.