Forum Moderators: coopster

Message Too Old, No Replies

Constructing Variable name

using value of 2 different variables

         

xentsear

8:13 am on Aug 18, 2003 (gmt 0)

10+ Year Member



I wanted to construct a variable name from the value of two other variables. For example,

$a = abc;
$b = def;

and making $somevariable = $abcdef;

Is it possible? Thanks for your attention.

vincevincevince

11:37 am on Aug 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



do you mean:
$somevariable=$a.$b
?

xentsear

12:29 pm on Aug 18, 2003 (gmt 0)

10+ Year Member



Hmm... no, as the output will be abcdef. I wanted the output to be a variable.

For example,

content.php
$abcdef = "Result";
$bcdefg = "Result2";

table.php
<table><tr><td><?=$somevariable?></td></tr></table>

get.php
require ("content.php");
require ("table.php");
$a = $_GET["a"]; //where a will be abc
$b = $_GET["b"]; //where b will be def

$somevariable = //Combined of $a and $b, and is a variable so it can be called in content.php

Hope is not confusing... i have my own reasons for making it this way :)

rpking

12:30 pm on Aug 18, 2003 (gmt 0)

10+ Year Member



You need variable variables [phpbuilder.com]

xentsear

1:33 pm on Aug 18, 2003 (gmt 0)

10+ Year Member



Hmm....but any idea how to combined the two variables into one variable?

$$a will be equal $abc and $$b will be equal to $def. But how do i make them into one single variable? Sorry i'm a little slow in taking in stuff :)

xentsear

1:39 pm on Aug 18, 2003 (gmt 0)

10+ Year Member



Hmm...oh i get it..would it be something like :

$temp = $a . $b;
$somevariable = $$temp;

Lol i think this works thanks for all your help :)

jatar_k

4:48 pm on Aug 18, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



or

$a = abc;
$b = def;

${$a . $b} = $a . $b;