Posted By

mloberg on 02/19/11


php variables array arrays to convert

Versions (?)

Convert Array To Variables

 / Published in: PHP

This simply takes an array and coverts it to variables. E.g. If you had an array, $array = array("key" => "value"), after running this script, $key would be "value".

  1. <?php
  2. foreach($array as $key => $value){
  3. $$key = $value;
  4. }
  6. // simple as that

Report this snippet  


RSS Icon Subscribe to comments
Posted By: FatFolderDesigner on February 19, 2011

Even simple if you just use the PHP extract() function, no loop.

Posted By: mloberg on March 3, 2011

Thanks for the tip. extract() is a lot shorter.

You need to login to post a comment.