Page 1 of 1

variable built from variables

Posted: Tue Jun 14, 2005 5:38 am
by rsmarsha
I want do to this:

make a variable from 2others

Code: Select all

//existing
$first = $second2text;
//i have the variable
$_POST['number'];
// i want to put them together in the form
$first = $second$_POST['number']text;
//with the $_POST['number'] replacing the 2 in the first line
Is this possible?

Posted: Tue Jun 14, 2005 6:20 am
by phpScott
not that I have heard off.

what is it your are trying to accomplish other then makeing a weird variable replacement.

variable, varibles won't help.

Posted: Tue Jun 14, 2005 6:23 am
by rsmarsha
Was just trying to cut down some code without having to re-order some files :) Just been lazy, hehe. I'll just recode them will be better in the long run.

Posted: Tue Jun 14, 2005 6:29 am
by timvw

Code: Select all

$first = ${"second" . $_POST['number'] . "text"};

Here is another example ;)

Code: Select all

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);

$second0text = "mike";

for ($number = 0; $number < 2; ++$number)
{
        $first = ${"second".$number."text"};
        echo $first;
        echo "<br/>";
}
?>

Posted: Tue Jun 14, 2005 6:50 am
by phpScott
if that accomplishes what he is looking for then timvw; then you the man. :!: