Re: [PHP] Variable variables into an array.
On 11 August 2010 13:58, Bob McConnell wrote: > From: Richard Quadling > >> Quick set of eyes needed to see what I've done wrong... >> >> The following is a reduced example ... >> >> > $Set = array(); >> $Entry = 'Set[1]'; > ^^ > Shouldn't that be $Set[1]? > >> $Value = 'Assigned'; >> $$Entry = $Value; >> print_r($Set); >> ?> > > Bob McConnell > No. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Variable variables into an array.
From: Richard Quadling > Quick set of eyes needed to see what I've done wrong... > > The following is a reduced example ... > > $Set = array(); > $Entry = 'Set[1]'; ^^ Shouldn't that be $Set[1]? > $Value = 'Assigned'; > $$Entry = $Value; > print_r($Set); > ?> Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable variables into an array.
On 10 August 2010 18:08, Andrew Ballard wrote: > On Tue, Aug 10, 2010 at 12:23 PM, Richard Quadling > wrote: >> On 10 August 2010 16:49, Jim Lucas wrote: >>> Richard Quadling wrote: Hi. Quick set of eyes needed to see what I've done wrong... The following is a reduced example ... >>> $Set = array(); $Entry = 'Set[1]'; $Value = 'Assigned'; $$Entry = $Value; print_r($Set); ?> The output is an empty array. Examining $GLOBALS, I end up with an entries ... [Set] => Array ( ) [Entry] => Set[1] [Value] => Assigned [Set[1]] => Assigned According to http://docs.php.net/manual/en/language.variables.basics.php, a variable named Set[1] is not a valid variable name. The [ and ] are not part of the set of valid characters. In testing all the working V4 and V5 releases I have, the output is always an empty array, so it looks like it is me, but the invalid variable name is an issue I think. Regards, Richard. NOTE: The above is a simple test. I'm trying to map in nested data to over 10 levels. >>> >>> For something like this, a string that looks like a nested array reference, >>> you might need to involve eval for it to "derive" that nested array. >>> >> >> I'm happy with that. >> >> It seems variable variables can produce variables that do not follow >> the same naming limitations as normal variables. >> > > It would seem so. If eval() works, can you rearrange the strings a > little to make use of parse_str() and avoid the use of eval()? > > Andrew > php -r "parse_str('a[1][2][3]=richard quadling'); var_dump($a);" outputs ... array(1) { [1]=> array(1) { [2]=> array(1) { [3]=> string(16) "richard quadling" } } } Perfect. Thanks. -- Richard Quadling. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable variables into an array.
On Tue, Aug 10, 2010 at 12:23 PM, Richard Quadling wrote: > On 10 August 2010 16:49, Jim Lucas wrote: >> Richard Quadling wrote: >>> >>> Hi. >>> >>> Quick set of eyes needed to see what I've done wrong... >>> >>> The following is a reduced example ... >>> >>> >> $Set = array(); >>> $Entry = 'Set[1]'; >>> $Value = 'Assigned'; >>> $$Entry = $Value; >>> print_r($Set); >>> ?> >>> >>> The output is an empty array. >>> >>> Examining $GLOBALS, I end up with an entries ... >>> >>> [Set] => Array >>> ( >>> ) >>> >>> [Entry] => Set[1] >>> [Value] => Assigned >>> [Set[1]] => Assigned >>> >>> >>> According to http://docs.php.net/manual/en/language.variables.basics.php, >>> a variable named Set[1] is not a valid variable name. The [ and ] are >>> not part of the set of valid characters. >>> >>> In testing all the working V4 and V5 releases I have, the output is >>> always an empty array, so it looks like it is me, but the invalid >>> variable name is an issue I think. >>> >>> Regards, >>> >>> Richard. >>> >>> NOTE: The above is a simple test. I'm trying to map in nested data to >>> over 10 levels. >> >> For something like this, a string that looks like a nested array reference, >> you might need to involve eval for it to "derive" that nested array. >> > > I'm happy with that. > > It seems variable variables can produce variables that do not follow > the same naming limitations as normal variables. > It would seem so. If eval() works, can you rearrange the strings a little to make use of parse_str() and avoid the use of eval()? Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable variables into an array.
On 10 August 2010 16:49, Jim Lucas wrote: > Richard Quadling wrote: >> >> Hi. >> >> Quick set of eyes needed to see what I've done wrong... >> >> The following is a reduced example ... >> >> > $Set = array(); >> $Entry = 'Set[1]'; >> $Value = 'Assigned'; >> $$Entry = $Value; >> print_r($Set); >> ?> >> >> The output is an empty array. >> >> Examining $GLOBALS, I end up with an entries ... >> >> [Set] => Array >> ( >> ) >> >> [Entry] => Set[1] >> [Value] => Assigned >> [Set[1]] => Assigned >> >> >> According to http://docs.php.net/manual/en/language.variables.basics.php, >> a variable named Set[1] is not a valid variable name. The [ and ] are >> not part of the set of valid characters. >> >> In testing all the working V4 and V5 releases I have, the output is >> always an empty array, so it looks like it is me, but the invalid >> variable name is an issue I think. >> >> Regards, >> >> Richard. >> >> NOTE: The above is a simple test. I'm trying to map in nested data to >> over 10 levels. > > For something like this, a string that looks like a nested array reference, > you might need to involve eval for it to "derive" that nested array. > I'm happy with that. It seems variable variables can produce variables that do not follow the same naming limitations as normal variables. -- Richard Quadling. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable variables into an array.
Richard Quadling wrote: Hi. Quick set of eyes needed to see what I've done wrong... The following is a reduced example ... The output is an empty array. Examining $GLOBALS, I end up with an entries ... [Set] => Array ( ) [Entry] => Set[1] [Value] => Assigned [Set[1]] => Assigned According to http://docs.php.net/manual/en/language.variables.basics.php, a variable named Set[1] is not a valid variable name. The [ and ] are not part of the set of valid characters. In testing all the working V4 and V5 releases I have, the output is always an empty array, so it looks like it is me, but the invalid variable name is an issue I think. Regards, Richard. NOTE: The above is a simple test. I'm trying to map in nested data to over 10 levels. For something like this, a string that looks like a nested array reference, you might need to involve eval for it to "derive" that nested array. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Variable variables into an array.
Hi. Quick set of eyes needed to see what I've done wrong... The following is a reduced example ... The output is an empty array. Examining $GLOBALS, I end up with an entries ... [Set] => Array ( ) [Entry] => Set[1] [Value] => Assigned [Set[1]] => Assigned According to http://docs.php.net/manual/en/language.variables.basics.php, a variable named Set[1] is not a valid variable name. The [ and ] are not part of the set of valid characters. In testing all the working V4 and V5 releases I have, the output is always an empty array, so it looks like it is me, but the invalid variable name is an issue I think. Regards, Richard. NOTE: The above is a simple test. I'm trying to map in nested data to over 10 levels. -- Richard Quadling. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php