Wednesday, December 7, 2011

Concatenate Variables names in PHP

This is for when you want to have a variable to be part of a new variable nam

$var1 = 'category';
$var2 = 'one';
${$var1.$var2} = 'sometext';

//OR
$var1 = 'category';
$var2 = 'one';
$var = $var1.$var2;
$$var = 'sometext';

/*
this creates the var $categoryone
with with the value of 'sometext'
*/

No comments:

Post a Comment