On Thu, 2006-12-21 at 14:54 +0200, Yonatan Ben-Nes wrote:
> Hi all,
>
> I got a problem with creating a multidimensional array which it's size is
> unknown.
> I already made it work like this (example):
> <?php
> $array = array('six','five','four','three','two','one');
>
> for ($i = count($array)-1; $i >= 0; $i--) {
> $array_keys_string_representation .= '["'.$array[$i].'"]';
> }
>
> eval('$new_array'.$array_keys_string_representation.'["node_title"] =
> "string value";');
> ?>
<?php
$new = array();
$ref = &$new;
foreach( array_reverse( $array ) as $key )
{
$ref[$key] = array();
$ref = &$ref[$key];
}
$ref['node_title'] = 'string value';
print_r( $new );
?>
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php