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.

Share:
13,757
user531380
Author by

user531380

Updated on June 30, 2022

Comments

  • user531380
    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
    cbrandolino over 12 years
    OP wanted to output the vas's name.
  • cbrandolino
    cbrandolino over 12 years
    Not really. Op wanted to output the string "$blurb_78" with the "78" part given as a variable.
  • Shef
    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
    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
    cbrandolino over 12 years
    It's echoing the var's value, while I thought OP wanted its name to be displayed.