This article is not about the use of split and explode, but about a special situation.
Example.
$ Array = array (2, 'A' => array ('B' => 'C '));
// List of deep keys
$ Keys = array ('A', 'B ');
// Value
$ Vals = 'X ';
// The problem is how to change the value of the corresponding array $ array according to the $ keys array (dynamic)
// For example, you must change the value of $ array ['a'] ['B'] from 'C' to 'x'
// Note that $ keys is dynamic or array ('A', 'C', 'x', 'D ').
// You must set $ array ['a'] ['C'] ['X'] ['D'] To 'x ';
At first glance, it seems very simple. Can eval solve it? Indeed, but eval is strictly prohibited on many servers,
Except for eval, is there a preg_replace + e modifier? Yes, but there are always security concerns,
Isn't it as dangerous to inject system/exec/shel_exec Function + system commands as eval?
Finally, we thought of parse_str, which is relatively safe.
$ Array = array (2, 'A' => array ('B' => 'C '));
// List of deep keys
$ Keys = array ('A', 'B ');
// Value
$ Vals = 'X ';
// Convert string to array
Parse_str ('array ['. implode ('] [', $ keys).'] = '. $ vals );
Print_r ($ array );