Jim Lucas wrote:
Martin Zvarík wrote:
Nope, you have to use the eval() everytime for read/write.



Wrong.  Their is always more then one way to skin a cat!

<?php

$node = '[5][1][]';
$text = 'some text';

preg_match_all('|\[([^\]\[]*)\]|', $node, $matches, PREG_PATTERN_ORDER);

$recursive = $matches[1];

$recursive = array_reverse($recursive);

$index = array_shift($recursive);

$in = array((int)$index => $text);
$out = array();

foreach ( $recursive AS $index ) {

    $out = array();

    $out[(int)$index] = $in;

    $in = $out;
}

print_r($out);
?>



Even slimmer

<?php

$node = '[5][1][]';
$text = 'some text';

preg_match_all('|\[([^\]\[]*)\]|', $node, $matches, PREG_PATTERN_ORDER);

$recursive = $matches[1];

$recursive = array_reverse($recursive);

foreach ( $recursive AS $index ) {

        $out = array();

        $out[(int)$index] = $text;

        $text = $out;
        
}

print_r($out);
?>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to