Php 如何将变量与下划线和其他单词组合?
我需要将$variable与下划线和以下单词组合在一起: $agent=代理id 单词是“谢绝” 我怎么能这样做?像这样Php 如何将变量与下划线和其他单词组合?,php,variables,concatenation,Php,Variables,Concatenation,我需要将$variable与下划线和以下单词组合在一起: $agent=代理id 单词是“谢绝” 我怎么能这样做?像这样 $agent_declined = "foobar"; $id = "declined"; $varname = "\$agent_" . $id $newvar = $$varname; // should give foobar 我建议不要使用double$$,这样会让人困惑。像这样吗 $agent_declined = "foobar"; $id = "decline
$agent_declined = "foobar";
$id = "declined";
$varname = "\$agent_" . $id
$newvar = $$varname; // should give foobar
我建议不要使用double$$
,这样会让人困惑。像这样吗
$agent_declined = "foobar";
$id = "declined";
$varname = "\$agent_" . $id
$newvar = $$varname; // should give foobar
我建议不要使用double
$
,这会让人困惑。像这样:$newvar=$agent。“_谢绝”代码>
在PHP中,您可以使用如下方式组合字符串:$newvar=$agent。“_谢绝”代码>
在PHP中,您可以使用
组合字符串。请使用串联:
<?php
$newvar = $agent . "_declined";
?>
阅读使用连接:
<?php
$newvar = $agent . "_declined";
?>
阅读试试这个:
${$variableName.'_declined'} = 'foo';
有关详细信息,请参见尝试以下操作:
${$variableName.'_declined'} = 'foo';
有关更多信息,请参见查看您对所要查找的内容似乎存在分歧。你能提供一个例子和预期的结果吗?看,似乎有一个分歧,你到底在寻找什么。你能提供例子和预期结果吗?