构造php变量的名称

时间:2012-08-31 10:01:28

标签: php

$service3_step1_person = ‘999’;    
echo $service3_step1_person;    //999

然后......

$service = "service3";    
echo "$".$service."_step1_person;  //$service3_step1_person

它不会给我 999 ,只需给我一串$service3_step1_person

如何让字符串成为新的变量名?谢谢!

3 个答案:

答案 0 :(得分:5)

echo ${$service."_step1_person"};

答案 1 :(得分:2)

变量变量:

$service3_step1_person = ‘999’;
$service = "service3";
$variableName = "{$service}_step1_person";  
echo $$variableName; // 999

答案 2 :(得分:0)

试试这个:

 $service = "service3";
 $temp = "_step1_person";
 echo ${$service.$temp};