Re: Variable question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Oct 1, 2011 at 10:59 AM, Ron Piggott <ron.php@xxxxxxxxxxxxxxxxxx>wrote:

> If $correct_answer has a value of 3 what is the correct syntax needed to
> use echo to display the value of $trivia_answer_3?


You can use variable variables [1] to access the variable by building its
name in a string:

    $name = 'trivia_answer_' . $correct_answer;
    echo $$name;

Peace,
David

[1] http://php.net/manual/en/language.variables.variable.php

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux