lalabored Posted April 30, 2007 Share Posted April 30, 2007 How do I store the name of a variable into a text string? For example $wonderfulday = "value"; I want to be able to take $wonderfulday and turn it into "wonderfulday" or $variable = "wonderfulday"; or something like that. Link to comment https://forums.phpfreaks.com/topic/49374-solved-name-of-variable-into-text-string/ Share on other sites More sharing options...
papaface Posted April 30, 2007 Share Posted April 30, 2007 http://us2.php.net/manual/en/language.variables.php#49997 Link to comment https://forums.phpfreaks.com/topic/49374-solved-name-of-variable-into-text-string/#findComment-241923 Share on other sites More sharing options...
trq Posted April 30, 2007 Share Posted April 30, 2007 Sorry, your question isn't real clear. You want the value of a variable to be the same as its name? $wonderfulday = "wonderfulday"; I'm not sure what you mean. Maybe your looking for get_defined_vars? Link to comment https://forums.phpfreaks.com/topic/49374-solved-name-of-variable-into-text-string/#findComment-241924 Share on other sites More sharing options...
lalabored Posted April 30, 2007 Author Share Posted April 30, 2007 http://us2.php.net/manual/en/language.variables.php#49997 Thanks! I got this code... <?php function vname(&$var, $scope=false, $prefix='unique', $suffix='value') { if($scope) $vals = $scope; else $vals = $GLOBALS; $old = $var; $var = $new = $prefix.rand().$suffix; $vname = FALSE; foreach($vals as $key => $val) { if($val === $new) $vname = $key; } $var = $old; return $vname; } ?> And it works! I don't understand it at all though... Link to comment https://forums.phpfreaks.com/topic/49374-solved-name-of-variable-into-text-string/#findComment-241934 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.