![]() |
Home
iRate! IceMelon IM Tutorials Headlines CoolSites PHP Functions |
Most Referenced Functions » google_pagerank() » preg_replace() » imagecreatefrompng() » site_pageranks() » imagepng() » imagedestroy() » imagestring() » imagecolorallocate() » htmlentities() » preg_match() » fopen() » header() » getimagesize() » htmlspecialchars() » ob_start() » session_start() » strstr() » preg_match_all() » ob_flush() » strpos() » flush() » setcookie() » str_replace() » array2vars() » nl2br() » preg_split() » ereg() » ereg_replace() » urlencode() » readgzfile() Become a sponsor for $15/month. Link is sitewide - PR5 homepage, 20+ PR4 pages, 90+ PR3 pages. Email dave[AT]icemelon[D0T]c0m. |
PHP Functions
Function: array2vars By dave Note! This function is not a built-in PHP function. To use it, you will need to copy the source code (located at the bottom of this page) into your script. array2vars -- Converts an array into a set of variables, where the keys become the variables' names. Descriptionvoid array2vars ( array KeysWithValues )This function can be useful in converting your $_POST values into distinct variables. This way, you can just type $keyName instead of $_POST['keyName']. Other similar arrays include $_GET, $_REQUEST, $_SESSION, $_COOKIE; and an array (or row) fetched from your mySQL database, as exemplified in example 2. Note! It was pointed out by a visitor that the function extract (see related functions) does the exact same thing. Example 1. array2vars() example <?php $icemelon = Array('ice' => 'melon', 'foo' => 'fighters'); array2vars($icemelon); echo "$ice, $foo "; // outputs: melon, fighters ?> Example 2. <?php $q = mysql_query($query); while($row = mysql_fetch_array($q)) { array2vars($row); // use variables // .... } ?> Source Code<?php function array2vars($arr) { foreach($arr AS $key=>$var) { global $$key; $$key = $var; } } ?> Related Function(s) |