1

I have this string: 1[2[5,6]],4,7[8,10] It represents nested IDs to be used to build an array of navigation items.

I need to parse this string and create a multidimensional array of its values. This will probably take several consecutive expressions and loops to build.

The end product would be an array like this:

1 =>
     2 =>
          5
          6
4
7 => 
     8
     10

I think all I need is an expression that will split the string on commas not inside of a set of brackets. I would then loop over the substrings with the same pattern.

1 Answer 1

2

I realize this doesn't directly answer your question, but there's really no point in making your own parser. Just store the data in a JSON string instead.

http://php.net/json-encode

http://php.net/json-decode

Sign up to request clarification or add additional context in comments.

1 Comment

i considered json, but can you nest objects in json?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.