title: Can you get a variable name as a string in PHP? (And should you?)
body: <p>Say you have several large arrays of variables (which generally are strings), and you want to change how they are displayed on certain pages – for example by concatenating each of them with <code>$prefix</code> and <code>$suffix</code>:</p>
  
  <pre><code>$arr = array($foo, $bar, $baz)
  
  $foo_display = $prefix . $foo . $suffix
  $bar_display = $prefix . $bar . $suffix
  $baz_display = $prefix . $baz . $suffix
  </code></pre>
  
  <p>How would you avoid having to make all these assignments manually? I originally assumed there would be some function which would return a variable's name as a string (call it "varname()"), in which case the code might look like this:</p>
  
  <pre><code>foreach ($arr as &amp;$value) {
      ${varname($value)."_display"} = $prefix . $value . $suffix
  }
  </code></pre>
  
  <p>But I haven't been able to find such a function, and people in <a href="https://stackoverflow.com/questions/255312/how-to-get-a-variable-name-as-a-string-in-php">this similar thread</a> seemed to think the entire concept was suspect. </p>
  
  <p>PS: I'm new to programming, sorry if this is a dumb question :)</p>