if ($key === '') { continue; } if (is_numeric($key[0])) { $key = '_' . $key; } $output[$key] = $value; } return $output; } // im running this test in a function, so that get_defined_vars() just gives me a local scope // i didnt want to sift through $_SERVER, $_SESSION, and so on function testme(array $extracted) { //extract(prepareForExtract($extracted), EXTR_PREFIX_SAME | EXTR_PREFIX_INVALID | EXTR_REFS, 'test'); extract(prepareForExtract($extracted), EXTR_PREFIX_SAME | EXTR_REFS, 'test'); var_dump(get_defined_vars()); } foreach ($test as $file) { testme($file); } /* Conclusion: get variables you want to extract into an array find a prefix that you want to append in case of collisions, such as $prefix = 'stim_' then use: extract(prepareForExtract($extracted), EXTR_PREFIX_SAME | EXTR_REFS, $prefix); the EXTR_REFS pulls everything as a reference, so you can modify $test or $cue and see the results in the output */
<?php define('EOL', "\n"); $data = 'a=1&b=2&c=3'; echo 'global scope', EOL; echo 'parse_data(): ', $data, EOL; parse_str($data); if (isset($b)) { echo 'isset b=' . $b, EOL; } else { echo 'no b=' . $b, EOL; } echo EOL; echo 'within function', EOL; testme(); function testme() { $data = 'a=1&b=2&c=3'; echo 'parse_data(): ', $data, EOL; parse_str($data); if (isset($b)) { echo 'isset b=' . $b, EOL; } else { echo 'notset b=' . $b, EOL; } if (isset($b)) { echo 'isset b=' . $b, EOL; } else { echo 'no b=' . $b, EOL; } }