I try to merge or combine two variables into one new variable.
My Snippet looks like this:
<?php
$text_headline = "dat headline";
for ($i = 1; $i <= $text_text; $i++) {
echo '$text_headline.$i';
}
?>
But this didn't work, of course.
I also tried
$text_headline_combo = {$text_headline.$i};
But doesn't work as well. It sends me an error message.
Parse error: syntax error, unexpected '{' in /...
Does anybody have other solution for me? Much thanks in advance!
String interpolation is only recognized in double quotes.
Try
echo "$text_headline.$i";
If I understand your comments correctly, you have a series of headlines like
$text_headline1 = 'Some headline';
$text_headline2 = 'Another headline';
You want to output them in your loop. You can use a double $
<?php
$text_headline1 = 'Some headline';
$text_headline2 = 'Another headline';
for ($i = 1; $i <= $text_text; $i++) {
$headlineVar = 'text_headline' . $i;
echo $$headlineVar;
}
?>
This is called Variable variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With