Make all new variables, dynamically, from arrays (Even the $_SUPERGLOBALS)... wordy title

<?php $size = 'large'; $GET_array = $_GET; // for example... $_GET = array("color" => "blue", // "size" => "medium", // "shape" => "sphere"); extract($GET_array, EXTR_PREFIX_SAME, 'wddx'); echo "$color, $size, $shape, $wddx_big\n"; // blue, large, sphere, medium /* FTM: The $size wasn't overwritten because we specified EXTR_PREFIX_SAME, which resulted in $wddx_size being created. If EXTR_SKIP was specified, then $wddx_size wouldn't even have been created. EXTR_OVERWRITE would have caused $size to have value "medium", and EXTR_PREFIX_ALL would result in new variables being named $wddx_color, $wddx_size, and $wddx_shape. */ $info = array('coffee', 'brown', 'caffeine'); // Listing all the variables list($drink, $color, $power) = $info; echo "$drink is $color and $power makes it special.\n"; // Listing some of them list($drink, , $power) = $info; echo "$drink has $power.\n"; // Or let's skip to only the third one list( , , $power) = $info; echo "I need $power!\n"; // list() doesn't work with strings list($bar) = "abcde"; var_dump($bar); // NULL

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.