1

How does php handle something like this...

$blah = "Testing a variable"; 
$$blah = "test"; 

What would my new variable name be?

Dalton Conley
  • 1,562
  • 2
  • 25
  • 35

4 Answers4

9

Everything you need to know about variable variables at http://www.php.net/manual/en/language.variables.variable.php, except for one thing: don't use them.

Rafe Kettler
  • 69,672
  • 18
  • 145
  • 147
4

echo ${'Testing a variable'};

However, you don't want to do this in practice. It makes for unmaintainable, bug-prone code.

webbiedave
  • 46,141
  • 7
  • 83
  • 96
1

The variable $blah must contain a valid variable name.

This will tell you about variables: http://www.php.net/manual/en/language.variables.basics.php

zsalzbank
  • 9,140
  • 1
  • 23
  • 38
0

Not really an answer, but...

<?php 
function I_love_you()
{
    return "haha";
}

$haha = "HoHoHo";
$tom = "I_love_you";
$blah = "tom";

echo ${$$blah()};
?>
DampeS8N
  • 3,571
  • 14
  • 19