Sorry couldn't think of a way to describe in the title. Ok here is what i want to achieve $stuff1 = "This is stuff 1"; $num = 1; Now echo '$stuff'.$num ; //Should echo This is stuff 1 How can this be done ?
Not trying to be offensive. But that is the strangest method I've ever seen. I thought this would of been the more "normal" method? $stuff = 'This is stuff'; $num = 1; echo $stuff .' '. $num; // This is stuff 1 PHP: Either way, both works.
You don't even need the apostrophe's... $stuff = "This is stuff"; $num = "1"; echo $stuff . $num; PHP:
I'm going to disagree, As far I can see, Clarky's method is the only one that would work in all circumstances in which you would use it. ... and it's what I would do myself, so it's got to be good </arrogance> Dan
I think there's some confusion as to what is trying to be achieved. I believe the question was how to use a variable in the name of another variable - e.g. if $num was 2, the script would print out whatever the variable $stuff2 contains, not merely the contents of $stuff followed by the contents of $num.
just doing this like C king: it is easy. because $num variable automatically convered from integer to string.
No, Rodney and Clarky has hit the nail on the head (by judging the original post.) Say we then had: $stuff1 = 'This is just random fluff'; $stuff2 = 'This is more random fluff'; $num = 1; Now echo ${'stuff' . $num}; Would return: This is just random fluff - The intended output. Whereas: echo $stuff .' '. $num; Would return a notice and only : ' 1' Dan.
Let' make it more funny ) <?php class stuff { function complicated_life($here_your_stuff) { if($here_your_stuff) { for($complicator=1;$complicator<=10000;complicator++) { $get_long_life.="<br>".$complicator."<br>"; } } return "This is long stuff".$get_long_life; } } ?>