Re: Passing array names - a better way please

From: Date: Thu, 06 Sep 2001 00:46:51 +0000
Subject: Re: Passing array names - a better way please
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-66137@lists.php.net to get a copy of this message
Hi To briefly summarise the thread - I am trying to find a way for calling functions to store values in an n dimesional static aray within a cache function, so that the calling functions can manage the cached values through set/ get / is_locked / is_dirty etc helper functions. The problem is how to pass the values in to the static array in the cache. Variable variables don't seem to work with arrays, and I can't find a way to get eval( ) to work either. I am looking to create a static array inside the cache that will work like this: $data['key']['key2']['value'] = 'my old val' ; $data['key']['key2']['is_locked'] = FALSE ; $data['key']['key2']['is_dirty'] = TRUE ; etc etc I have found a rather crude mechanism that does work - but there must surely be a better way. Here is a simple example of the mechanism, which uses variable-length argument lists. <?php set( 'my new val', 'key', 'key2' ) ; function set( $value ) { $args = func_get_args( ) ; $data['key']['key2']['value'] = 'my old val' ; $data = array( $args[1] => array( $args[2] => array( 'value' => $value ) ) ) ; // Check what we have in the array $result = $data['key']['key2']['value'] ; echo( "Result is: $result<br>" ) ; ?> This is hardly pretty - I am sure I must be missing something better. I would be more than grateful for any help with this Thanks Geoff Caplan

« previous php.general (#66137) next »