note 43995 added to language.variables

From: Date: Mon, 12 Jul 2004 03:40:43 +0000
Subject: note 43995 added to language.variables
Groups: php.notes 
Request: Send a blank email to php-notes+get-73074@lists.php.net to get a copy of this message
I was bored (nothing new :)) so I tried to code few extraodinary lines and somehow come with something I could not explain at first. Here is the code: <?php $x= 'a'; $$x= 'b'; echo $x . "\n"; echo $a . "\n"; echo $$x . "\n"; $x= $$x ; echo $x . "\n"; echo $a . "\n"; echo $$x . "\n"; ?> With out running the code can you predict what the output would be? Careful now! ----------------------------------------------------------- The explanation: $x= $$x // $x now points to the value b The last line takes the value of $x which is 'b' and creates a variable variable $b which is NULL. Try adding this line of code before the last line: $b= 'Ah ha!'; and run the code again. Regards, drenintell ---- Manual Page -- http://www.php.net/manual/en/language.variables.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43995 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43995&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43995&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#73074) next »