home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / Asociative.php < prev    next >
Encoding:
Text File  |  2001-07-02  |  875 b   |  31 lines

  1.     //**************************************
  2.     //     
  3.     // Name: Asociative array to global vari
  4.     //     ables
  5.     // Description:By Ondra Zizka. Takes an 
  6.     //     asociative array and defines variables n
  7.     //     amed by arr's field names, opt. suffixes
  8.     //     and preffixes. arr["hi"]=="there"; <b
  9.     //     r> arr2vars($arr, "say_", "_1"); <
  10.     //     br> //-> $say_hi_1=="there" <br
  11.     //     >
  12.     // By: PHP Code Exchange
  13.     //**************************************
  14.     //     
  15.     
  16.     <?
  17.     function arr2vars($arr, $pref="", $suff=""){
  18.     while (list($xkey, $val) = each($arr)){
  19.     //global ${$pref.$xkey.$suff};
  20.         eval("global \$$pref$xkey$suff;");
  21.         ${$pref.$xkey.$suff} = $val;
  22.     }
  23.     }
  24.     /* use:
  25.     $arr = Array("ahoj"=>"lidi", "jakse"=>"mate");
  26.     arr2vars($arr);
  27.     echo $ahoj;
  28.     */
  29.     ?>
  30.  
  31.