Re: Dynamically creating multi-array field

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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);
?>


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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux