mister_t101 Posted March 25, 2006 Share Posted March 25, 2006 is there a way to create a variable with the name of a value of another variable? for example $foo=1;dynamically create a variable named $1$foo+=1;dynamically create a variable named $2 Link to comment https://forums.phpfreaks.com/topic/5741-variable-names/ Share on other sites More sharing options...
kenrbnsn Posted March 25, 2006 Share Posted March 25, 2006 You probably want to look at [a href=\"http://us3.php.net/manual/en/language.variables.variable.php\" target=\"_blank\"]variable variables.[/a][code]<?php$one = 'two';$$one = 'three'; // this is equivalent to $two = 'three';echo '$one = ' . $one . '<br>';echo '$$one = ' . $$one . '<br>';echo '$two = ' . $two . '<br>';?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/5741-variable-names/#findComment-20470 Share on other sites More sharing options...
wildteen88 Posted March 25, 2006 Share Posted March 25, 2006 variables that start with a number are invalid so you might want to name your variables like so:$_1;$_2;etc.As they are valid Link to comment https://forums.phpfreaks.com/topic/5741-variable-names/#findComment-20526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.