Create new variables from array keys in PHP

<?php extract($array); ?>

http://php.net/manual/en/function.extract.php


You could do this:

foreach($foo as $k => $v) {
  $$k = $v;
}

A simple method is to use variable variables:

foreach($foo as $key => $value) {
   $$key = $value;
}

echo $first; // '1st'

Note that this is generally discouraged however. It would be better to alter your templating system to allow for variables to be scoped within the template. Otherwise you could have issues with collisions and have to test for their existence, etc.