Re: Dynamically creating multi-array field

From: Date: Mon, 27 Oct 2008 05:28:27 +0000
Subject: Re: Dynamically creating multi-array field
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-282467@lists.php.net to get a copy of this message
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); ?>

« previous php.general (#282467) next »