Re: [PHP] Passing array names into a function
Hi Geoff, @ 3:30:24 PM on 9/5/01, Geoff Caplan wrote: I think I am being dumb but I just can't figure out a way to do this: I have a static array inside a function, and I want caller to be able to set/get values in the array. Something like this: ?php data_store( set, my_array['key1']['key2'], my new value) function data_store( $action, $variable, $value ) { static my_array = array( ) ; if( $action == set ) { // set my new value } } ? I have been mucking about with eval( ) and with variable variables, but can't get it to work. Can some kind person point out what I am missing?? Is this what you're looking for? (sorry so messy; in a hurry) ?php $my_array = array('foo' = array('bar' = 'baz')); $my_var = 'peanuts'; print brBefore: . $my_array[foo][bar]; print brBefore: . $my_var; function data_store($action, $variable, $value ) { if($action == 'set') return $variable = $value; } data_store('set',$my_array[foo][bar],'ack'); data_store('set',$my_var,'peanut butter'); print brAfter: . $my_array[foo][bar]; print brAfter: . $my_var; ? -Brian -- PGP is spoken here: 0xE4D0C7C8 Please, DO NOT carbon copy me on list replies. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Passing array names into a function
Brian Thanks for the response, but unless I am misunderstanding, I don't think this is what I am after. Just to restate, I want to set up a module as a static data cache. The main function $my_cache will have a static array $data. There will be a set of helper functions to set values into $data, get values from $data, lock values, mark them as dirty etc. Calling functions will be able to store and manage values in the cache for other functions to access. I need to be able to pass an array addresse of n dimensions into $my_cache together with a value, and an action such as set, get, unset etc: $my_cache( set, ['key1']['key2'] , someval ) ; Then somehow, inside $my_cache, I need to assign the value to $data as follows: $data['key1']['key2'] = someval ; As I say, I have been mucking about with eval( ) and variable variables with no success. Guess I am having a bad brain day. Any help much appreciated - its getting late here and I am running out inspiration Thanks again Geoff Caplan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Passing array names into a function
Hi folks I think I am being dumb but I just can't figure out a way to do this: I have a static array inside a function, and I want caller to be able to set/get values in the array. Something like this: ?php data_store( set, my_array['key1']['key2'], my new value) function data_store( $action, $variable, $value ) { static my_array = array( ) ; if( $action == set ) { // set my new value } } ? I have been mucking about with eval( ) and with variable variables, but can't get it to work. Can some kind person point out what I am missing?? Thanks Geoff Caplan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]