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 "<br>Before: " . $my_array[foo][bar];
print "<br>Before: " . $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 "<br>After: " . $my_array[foo][bar];
print "<br>After: " . $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]

Reply via email to