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

进而...

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

它没有给我999,只是给我一串$service3_step1_person.

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

4

3 回答 3

5
echo ${$service."_step1_person"};
于 2012-08-31T10:06:35.483 回答
2

变量变量:

$service3_step1_person = ‘999’;
$service = "service3";
$variableName = "{$service}_step1_person";  
echo $$variableName; // 999
于 2012-08-31T10:05:14.010 回答
0

试试这个:

 $service = "service3";
 $temp = "_step1_person";
 echo ${$service.$temp};
于 2012-08-31T10:06:11.823 回答