Jump to content


Photo

variable names


  • Please log in to reply
2 replies to this topic

#1 mister_t101

mister_t101
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 25 March 2006 - 03:15 AM

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

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 25 March 2006 - 04:51 AM

You probably want to look at [a href=\"http://us3.php.net/manual/en/language.variables.variable.php\" target=\"_blank\"]variable variables.[/a]
<?php
$one = 'two';
$$one = 'three'; // this is equivalent to $two = 'three';
echo '$one = ' . $one . '<br>';
echo '$$one = ' . $$one . '<br>';
echo '$two = ' . $two . '<br>';
?>

Ken

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 March 2006 - 12:29 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users