PHP - Concatenating two variables

我只是一个虾纸丫 提交于 2019-12-06 08:42:48

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.

Try making an array:

$blurb = array();

$blurb[78] = "Lorem ipsum";

echo $blurb[$id];

You should use an associative array instead of variables in your case.

Check this article in PHP official documentation:

This is your answer:

 echo '$blurb_'.$id;

Still, an associative array is the way to go.

Try

<?php
$blurb_78 = 'Lorem ipsum dolor.';
$id = 78;
echo ${'blurb_'.$id};
?>

This should work:

echo ${'blurb_'.$id}

echo ${'blurb_'.$id};

Demo

Read more on the variable variables article.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!