PDA

View Full Version : Adding a variable onto the end of a variable


JohnDubya
04-26-2007, 06:18 PM
Is it possible to add a variable onto the end of a new variable? For instance, I want a bunch of variables that start with $error_ , but then have the name of the form input after that. But I can't find a way to do that dynamically. I tried something like:


$name = 'first_name';

$error.$name = '<img src="image.jpg" />';

But obviously, this doesn't work. Is there any way to do this or do something similar that I haven't thought of yet?

GJay
04-26-2007, 06:38 PM
$name='first_name';

${'error_'.$name} = '<img src="image.jpg" />';

echo $error_first_name;


should do it.

'Variable variables' is the term to look for, more here: http://uk.php.net/manual/en/language.variables.variable.php

JohnDubya
04-26-2007, 07:20 PM
Wow, you are freaking amazing! That did it! Thanks so much!!!