I have an array of strings that are formatted like this:
$strings = array(
"/user",
"/robot",
"/user/1",
"/user/2",
"/user/2/test",
"/robot/1"
);
What I need to do is turn this into an array of the following structure when I print_r()
it:
Array
(
[user] => Array (
[1] => array(),
[2] => Array (
[test] => array()
)
[robot] => Array (
[1] => array()
)
)
I know I need to explode the original string by delimiter /
. However my problem is how do I then build the dynamic array.
Please note that the strings could potentially have an unlimited amount of slashes.