PHP - Concatenating two variables
13,757
I think you mean a variable variable name like it is mentioned at the Variable variables page on the PHP site. In your case this should work fine:
echo ${'blurb_'.$id};
But I highly doubt your approach on this one.
Author by
user531380
Updated on June 30, 2022Comments
-
user531380 almost 2 years
I'm a newbie stumped on the following. If I'm including an external file on a page that contains the following variable:
$blurb_78 = "Lorem ipsum dolor.";
How can I echo $blurb_78 on the local page? (where the
78
part is a generated article ID set to a variable labeled,$id
)The following doesn't work:
echo $blurb_.$id;
Thanks much for your help.
-
cbrandolino over 12 yearsOP wanted to output the vas's name.
-
cbrandolino over 12 yearsNot really. Op wanted to output the string "$blurb_78" with the "78" part given as a variable.
-
Shef over 12 years@cbrandolino Huh? What is mine doing? I have even linked to a demo page so you can see how it's working. Edit: I see what you meant. I don't think OP was that PHP illiterate.
-
cbrandolino over 12 years... And I was wrong. I'm going to upvote a random other question of yours, since I downvoted this more than 7 minutes ago.
-
cbrandolino over 12 yearsIt's echoing the var's value, while I thought OP wanted its name to be displayed.