PHP - Automatically creating a multi-dimensional array
问题 So here's the input: $in['a--b--c--d'] = 'value'; And the desired output: $out['a']['b']['c']['d'] = 'value'; Any ideas? I've tried the following code without any luck... $in['a--b--c--d'] = 'value'; // $str = "a']['b']['c']['d"; $str = implode("']['", explode('--', key($in))); ${"out['$str']"} = 'value'; 回答1: This seems like a prime candidate for recursion. The basic approach goes something like: create an array of keys create an array for each key when there are no more keys, return the