Question:

Using a PHP variable in another viarable name...?

by  |  earlier

0 LIKES UnLike

Basically, can you a variable simiar to $row['ID'] as a number in another variable. So basically, for every ID there is in a MYSQL table, add that number on to the end of another variable name. So if $row['ID'] = 1 how would i get it so that instead of another variable being called $sql it's called $sql1 = whatever

 Tags:

   Report

1 ANSWERS


  1. $prepend = "sql"; // change this if you want

    $fieldName = "ID"; // change this if you want

    $value = $row[$fieldName]; // leave this

    // choose either of the below:

    $finalValue = "whatever";

    //$finalValue = $value;

    $varName = $prepend . $value;

    $$varName = $finalValue;

    foreach ($row as $key=>$val){

        $name = $prepend . $key;

        $$name = $val

    }

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.