There is a built-in function in PHP or something clean for convert multidimensional array string to array?
String like:
['text', 'te\'"x2t', "text", "te\"x'#t", true, True, [false, False, 100, +100], -100, + 10, - 20]
each value can be strings(+ escaped characters), boolean, int(+sign) and array which make it a multidimensional array.
To:
Array
(
[0] => text
[1] => te'"x2t
[2] => text
[3] => te"x'#t
[4] => 1
[5] => 1
[6] => Array
(
[0] =>
[1] =>
[2] => 100
[3] => 100
)
[7] => -100
[8] => 10
[9] => -20
)
I wrote a regex for this, which make match valid to the string under those statements. So it will not match if the string not follows after the rules.
(?<_ARRAY>\[\s*(?:(?:(?P>VALUE)|(?P>_ARRAY))\s*,\s*)*(?:(?:(?P>VALUE)|(?P>_ARRAY))\s*)\])
Now I want to save the values as they are, without any changes.
It can be done with eval, but far as I know, eval is risky and I wonder if there is a better solution for this.
if (preg_match('/(?<_ARRAY>\[\s*(?:(?:(?P>VALUE)|(?P>_ARRAY))\s*,\s*)*(?:(?:(?P>VALUE)|(?P>_ARRAY))\s*)\])/', $array))
eval("\$array = $array;");