how to combine variables with string and generate value
<?php
$bun1="home";
$x="1";
$h= "$"."bun".$x;
echo $h;
?>
I want print $bun1 with result home, but "1" in $bun1 be variable $x
how to combine variables with string and generate value
<?php
$bun1="home";
$x="1";
$h= "$"."bun".$x;
echo $h;
?>
I want print $bun1 with result home, but "1" in $bun1 be variable $x
What you're trying to do is called variable variables.
PHP.net has a whole page on it.
<?php
$bun1="home";
$x="1";
$h= ${"bun".$x};
echo $h;
?>
Thing is though, from a design standpoint, you're almost always doing it wrong if you're using variable variables. Use arrays instead:
<?php
$bun[1] = "home";
$x=1;
$h= $bun[$x];
echo $h;
?>
If you're just trying to learn, then okay, have at it.