PHP creating variables from strings and associative arrays

Often having the URL string you need to parse the URL string and to have the variables for each GET parameter. This is actually what PHP does when creating the $_GET “superglobal” variable. Here is the function behind it: parse_str

$url = "user=123&actionid=2345&status=yes&plantype=121&day=20110623";


print ($user);
<a rel="nofollow" href="http://
print ($actionid);

print ($status);

print ($plantype);

print ($day);

Also, when speaking of creating variables, I find the extract function being very handy.

$size = "large";

$var_array = array("color" => "blue",

"size"  => "medium",

"shape" => "sphere");

extract($var_array, EXTR_PREFIX_SAME, "wddx");

echo "$color, $size, $shape, $wddx_size\n";

The output for the last example will be: blue, large, sphere, medium


tags: & category: -