variable built from variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

variable built from variables

Post 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?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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/>";
}
?>
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

if that accomplishes what he is looking for then timvw; then you the man. :!:
Post Reply