title: How to convert a string with comma separated values into variables in php?
body: <p>For instance, suppose I had 3 columns in my database: <code>column1, column2, column3</code></p>
  
  <p>And I had 3 variables with the same name as that of the columns:</p>
  
  <pre><code>$column1 = 'Column 1 value';
  $column2 = 'Column 2 value';
  $column3 = 'Column 3 value';
  </code></pre>
  
  <p>So if I appended a '<code>$</code>' sign to the column names in a foreach loop, I'll get the variable names. </p>
  
  <pre><code>$string = "column1, column2, column3";
  
  function get_variable_names($string) {
      $array = explode(", ", $string); // Convert to array
  
      foreach ($array as $key =&gt; $value) {
          $array_values_with_dollar[] = '$'.$value;
      }
      $imploded = implode(", ", $array_values_with_dollar); // Convert to string again
      return $imploded;
  }
  
  $variable_string = get_variables($string);
  </code></pre>
  
  <p>Now, the value of <code>$variable_string</code> would be: <code>$column1, $column2, $column3</code>. (string).</p>
  
  <p>Would it be possible to output the real value of the variables such that:</p>
  
  <p><code>$variable_string =&gt; Column 1 value, Column 1 value, Column 1 value</code></p>
  
  <p>[ without using <a href="http://php.net/manual/en/function.eval.php" rel="nofollow noreferrer">eval()</a> ]</p>