Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

How do I pass and use a Variable Variable inside a PHP function

I'm trying to pass ${"variable_$i"} into a function so I can use $test. Within the function, I want to add html to ${"variable_$i"}.

Here's the error I'm receiving:

Parse error: syntax error, unexpected '$', expecting variable

My code:

// file.php
${"variable_$i"} = $test;
getCode(${"variable_$i"}, $result);

// function.php
// error
function getCode(${"variable_$i"}, $result) {
  if ($result->num_rows > 0) {
    $columns = 3;
    $x = 0;

    ${"variable_$i"} .= "<tr>";

    // more code
  }
}

How can I access this variable for use inside the function?

Thanks!

Comments