Re: Dynamically named variables and arrays.

From: Date: Wed, 21 May 2003 16:09:43 +0000
Subject: Re: Dynamically named variables and arrays.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-148427@lists.php.net to get a copy of this message
I'm not quite sure what you're trying to do, but this is performing a replace on a string, not a variable" $requiredPostFieldName = str_replace( "sales_data", "", "sales_data[area][2]" ); I believe this will set $requiredPostFieldName to "[area][2]" Also, you might want to try breaking the second line into multiple interim variables to get it working, then collapse it back to one line. (my desktop is currently PHP-challenged, so I can't test anything) --- Chris Boget <chris@wild.net> wrote: > I know this works: > > $varName = 'bob'; > ${$varName} = 'joe'; > > Now, what I'm hoping to to is take the same premis and apply it to > arrays (particularly POST). What I'm doing is creating form > element > names as follows: > > sales_data[area][1] > sales_data[area][2] > ... > sales_data[area][5] > > and so on. Upon form submission, we all know that PHP turns the > above into an array that I can iterate through and get the values. > Now, > I now the names of the form elements. So using that, I'm trying to > > access the value of the outermost element dynamically. To do that, > I'm > doing: > > <script language="php"> > > $requiredPostFieldName = str_replace( "sales_data", "", > "sales_data[area][2]" ); > $fieldVal = ${"_POST['sales_data']{$requiredPostFieldName }"}; > > </script> > > But that's not working. Should it? Am I doing something wrong? > Any > ideas or suggestions would be very much appreciated! > > Christoph > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > ===== Mark Weinstock mark_weinstock@yahoo.com *************************************** You can't demand something as a "right" unless you are willing to fight to death to defend everyone else's right to the same thing. *************************************** __________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com

« previous php.general (#148427) next »