Re: Creating multidimensional array

From: Date: Thu, 21 Dec 2006 13:19:17 +0000
Subject: Re: Creating multidimensional array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-246120@lists.php.net to get a copy of this message
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. | `------------------------------------------------------------'

« previous php.general (#246120) next »