For instance, suppose I had 3 columns in my database: column1, column2, column3
And I had 3 variables with the same name as that of the columns:
$column1 = 'Column 1 value';
$column2 = 'Column 2 value';
$column3 = 'Column 3 value';
So if I appended a '$' sign to the column names in a foreach loop, I'll get the variable names.
$string = "column1, column2, column3";
function get_variable_names($string) {
$array = explode(", ", $string); // Convert to array
foreach ($array as $key => $value) {
$array_values_with_dollar[] = '$'.$value;
}
$imploded = implode(", ", $array_values_with_dollar); // Convert to string again
return $imploded;
}
$variable_string = get_variables($string);
Now, the value of $variable_string would be: $column1, $column2, $column3. (string).
Would it be possible to output the real value of the variables such that:
$variable_string => Column 1 value, Column 1 value, Column 1 value
[ without using eval() ]