faqts : Computers : Programming : Languages : PHP : kms : General

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

13 of 15 people (87%) answered Yes
Recently 5 of 6 people (83%) answered Yes

Entry

How do I implement a variable variable?

Jan 16th, 2000 21:29
Nathan Wallace, Marc-Olivier Krahenbuhl,


A variable variable allows you to have a variable name that is set at
run time.  This can be implemented as follows:

    <?php

    // Set the variable name
    $var_name = 'myvariable';

    // Now you can access the variable $myvariable with
    $$var_name = 1;

    // So this will always work
    if ($$var_name == $myvariable) {
        echo "This will always be true since they are the same thing";
    }

    ?>