开发者

Appending a value of a variable to a variable name? [duplicate]

This question already has answers here: 开发者_如何转开发 Closed 10 years ago.

Possible Duplicate:

Can I use a generated variable name in PHP?

Am stuck here!

$part_one = "abc";
$v = "one";

echo $part_???; // should output "abc"

How do I modify ??? to reference $v?

Thanks!


You need variable variables:

echo ${'part_'.$v};
// or
$var = 'part_'.$v;
echo $$var;


$_part$v;? maybe idk. I know you can do this:

$vname="variable";
$$vname="hello";
echo $variable;

//WOULD output "hello"

try this:

$name="_part";
$name=$name . $v;
$$name=$value;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜