Jump to content

Archived

This topic is now archived and is closed to further replies.

mister_t101

variable names

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.