array name in variable variable 
Author Message
 array name in variable variable

        Hi everyone!

This could be cool, but it won't work as I want it to:
can I use a array indexing string as a variable variable, i.e.:

$arrayname = "_SESSION['HTHESA']";
$target = $arrayname."['".$key."']";

$$target = $$act;

print $target.' = '.$$target.'<br>';

This does not work as desired, the values I meant to put into
$_SESSION['HTHESA'] are not there.
Did I simply forget some more $'s, or is it not possible to reference an
array like this?

regards,
        Daniel

--
Daniel Krippner

Fraunhofer Institute for Solar Energy Systems ISE
Department Electrical Energy Systems (EES)
Team Storage Systems (SPS)

Heidenhofstrasse 2
D-79110 Freiburg, Germany
PHONE:  +49 (0) 761 4588-5313
FAX:    +49 (0) 761 4588-9313

WEB:     http://www.*-*-*.com/



Tue, 26 Apr 2005 18:31:32 GMT  
 array name in variable variable

Quote:
> This does not work as desired, the values I meant to put into
> $_SESSION['HTHESA'] are not there.
> Did I simply forget some more $'s, or is it not possible to reference an
> array like this?

Got it, missed the note in the doc

--
Daniel Krippner

Fraunhofer Institute for Solar Energy Systems ISE
Department Electrical Energy Systems (EES)
Team Storage Systems (SPS)

Heidenhofstrasse 2
D-79110 Freiburg, Germany
PHONE:  +49 (0) 761 4588-5313
FAX:    +49 (0) 761 4588-9313

WEB:    http://www.ise.fhg.de



Tue, 26 Apr 2005 19:53:59 GMT  
 array name in variable variable

Quote:

> Hi everyone!

> This could be cool, but it won't work as I want it to:
> can I use a array indexing string as a variable variable, i.e.:

> $arrayname = "_SESSION['HTHESA']";
> $target = $arrayname."['".$key."']";

> $$target = $$act;

> print $target.' = '.$$target.'<br>';

Note though that there are other ways of making completely unintelligible
code, you could for example use random names for your variables, like
$ah443l, $h_45__gg and so on. Also make sure to name all your functions to
cause the largest possible amount of confusion, e.g.: validateUser($user)
is of course the function that *deletes* the user, displayForm() exits the
system with a completely useless error message, e.g. "An error occured".

And finally, always comment the obvious, like this:
$i = 0; // Initialize $i with 0
$i++;   // Increment $i by one

But be careful never to explain things like invariants or
pre/post-conditions.

;)

Andr N?ss



Tue, 26 Apr 2005 23:01:25 GMT  
 array name in variable variable

Quote:

> Note though that there are other ways of making completely unintelligible
> code, you could for example use random names for your variables, like

Oh cmon :-)
I did not do this for fun, and the code was a condensed example to show
the point - the real thing does not declare the name of the variable one
line above it's use as a $$ ...

Besides, where's the fun if everybody can understand all my code at
first glance? Code that is too easily understood is probably not generic
enough ;)

cu
        Daniel

--
Daniel Krippner

Fraunhofer Institute for Solar Energy Systems ISE
Department Electrical Energy Systems (EES)
Team Storage Systems (SPS)

Heidenhofstrasse 2
D-79110 Freiburg, Germany
PHONE:  +49 (0) 761 4588-5313
FAX:    +49 (0) 761 4588-9313

WEB:    http://www.ise.fhg.de



Tue, 26 Apr 2005 23:22:36 GMT  
 array name in variable variable

Quote:


>> Note though that there are other ways of making completely
>> unintelligible code, you could for example use random names for your
>> variables, like

> Oh cmon :-)
> I did not do this for fun, and the code was a condensed example to
> show the point - the real thing does not declare the name of the
> variable one line above it's use as a $$ ...

> Besides, where's the fun if everybody can understand all my code at
> first glance? Code that is too easily understood is probably not
> generic enough ;)

> Daniel

Agreed. Some people are just plain jerks.


Wed, 27 Apr 2005 13:14:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Using a variable name for a variable name??

2. how to access arrays with variable for array names and index

3. access to array if name of array is variable

4. HOWTO: reference elements of an array if array name is in a variable

5. variable contents to variable name

6. getting variable name from the variable itself?

7. Variables containing variable names

8. name of a variable stored in another variable

9. Variable variable names?

10. values of variable variable-names

11. accessing to a variable by ref (variable is an array)

12. More About Array Names In String Variables

 

 
Powered by phpBB® Forum Software