我尝试将两个变量合并或合并为一个新变量。
我的代码段如下所示:
<?php
$text_headline = "dat headline";
for ($i = 1; $i <= $text_text; $i++) {
echo '$text_headline.$i';
}
?>
但这当然没有用。
我也试过
$text_headline_combo = {$text_headline.$i};
但是效果不佳。它向我发送错误消息。
解析错误:语法错误,/ ...中出现意外的'{'
有人对我有其他解决方案吗?提前非常感谢!
如果我正确理解您的评论,您将会看到一系列标题
$text_headline1 = 'Some headline';
$text_headline2 = 'Another headline';
您想在循环中输出它们。你可以用双$
<?php
$text_headline1 = 'Some headline';
$text_headline2 = 'Another headline';
for ($i = 1; $i <= $text_text; $i++) {
$headlineVar = 'text_headline' . $i;
echo $$headlineVar;
}
?>
这称为变量变量。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句