$service3_step1_person = ‘999’;
echo $service3_step1_person; //999
然后......
$service = "service3";
echo "$".$service."_step1_person; //$service3_step1_person
它不会给我 999 ,只需给我一串$service3_step1_person
。
如何让字符串成为新的变量名?谢谢!
答案 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};