Lets say we have variables: $page and $id. For example, $id=2. I wanna create new variable from existing variables $page and $id: $page2. how to do it? is it possible??
You can use curly brackets notation to create your variable name : http://codepad.org/L6B5vYdG
<?php
$number = 2;
${'page' . $number} = 20 ;
var_dump($page2);
?>
$page = 2;
${"page".$page} = "5555"; //we'll create variable from page + variable $page (2)
//$page2 has been created
$id = intval($page2); //$id will be 5555
You can simply concatenate them, or use the a string formatter such as sprintf
<?php
$page2 = $page . $id
# or
$page2 = snprintf("%s-%d", $page, $id);
You are asking for variable variables:
$page = 'x';
$id = 2;
${$page . $id} = 'lol'; // variable is named `$x2`
Or, simpler (I can't quite tell from your question):
$id = 2;
${'page' . $id} = 'lol'; // variable is named `$page2`
However, this is almost always a bad idea. Prefer arrays and/or objects.