Variable Variable Array Issue

Discussion in 'PHP' started by brandondrury, Jun 4, 2007.

  1. #1
    $catarray[Val]="row[ID]";
    $row[ID] = "it works,";
     
    echo ${$catarray[Val]};  // outputs nothing
    echo $row[ID];  //  outputs "  it works "
    PHP:
    I'm trying to construct variables in a function that dynamically constructs a table populated with MySQL.

    I need access to the array taken out of the MySQL database.

    Any ideas why this one doesn'twork?

    Brandon
     
    brandondrury, Jun 4, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Doesn't work because you are searching for a one dimensional variable with the name $row[id], not the 'id' element of the array $row.

    Why don't you do it like this? It seems variable variables are not necessary for what you are trying to do...
    $catarray['Val'] = 'ID';
    $row['ID'] = 'it works';
     
    echo $row[$catarray['Val']]; 
    PHP:
     
    krt, Jun 4, 2007 IP