Help with converting a string to an array

I am trying to convert a string to an array when, however, I want to create multidimensional arrays when the string has items in brackets.

For example, if the string as passed: (Mary Poppens) Umbrella (Color Yellow)

I would want to create an array that looks like this:

Array ( [0] => Array ( [0] => mary [1] => poppens) [1] => umbrella [2] => Array ( [0] => color [1] => yellow) )

I was able to get the data placed into an array through this:

preg_match_all('/\\(([A-Za-z0-9 ]+?)\\)/', stripslashes($_GET['q']), $subqueries);

But I am having trouble getting the items placed in the multidimensional arrays.

Any ideas?

I’m clueless where it comes to regex but this loop does what you asked for:

<?php
$string = "(Mary Poppens) Umbrella (Color Yellow)";
$op = '(';
$cp = ')';

while (strlen($string) > 0) {
    $open = strpos($string, $op);
    if($open !== FALSE) {
        $close = strpos($string, $cp, $open);
        if($close !== FALSE) {
            if($open != 0) {
                $x[] = trim(substr($string, 0, $open));
            }
            $str = trim(substr($string, $open, $close - $open), ' ()');
            $x[] = explode (' ', $str);
        }
        $string = trim(substr($string, $close+1, strlen($string) - $close));
    } else {
        $x[] = trim($string);
        $string = '';
    }
}