从变量更新数组

I have the 'path' to an array value stored in a variable, and I am trying to set the value. What I am trying to do is this:

$array['Breaks'][1]['In'] = "XXX";

However, I have ['Breaks'][1]['In'] stored in a variable. So I am essentially trying to do something like this:

$path = "['Breaks'][1]['In']";
$array.$path = "XXX";

This doesn't work though, and I'm not exactly sure how to go about making this work correctly.

Any suggestions?

Try doing this,

//This solution works if you are sure the length of $path_arr is going to be 3
$path = "['Breaks'][1]['In']";
$path_arr = explode(']', str_replace(array("['", "'", "["), '', $path)); 

$array[$path_arr[0]][$path_arr[1]][$path_arr[2]] = "XXX";
var_dump($array);

Demo

Try extracting each component of the $path variable into its own variable, or into an array ($pathArray below). So, if you had $pathArray[0] set to 'Breaks', $pathArray[1] set to 1, etc., you could do something like:

$array[$pathArray[0]][$[pathArray[1]][$[pathArray[2]] = "XXX";

Although this seems like an unusual way to go about things, and it might be worth re-thinking your approach entirely.

As long as the path string is not modifiable by users or parsed through previously you could just do:

eval("\$array".$path." = 'Value';");