Skip to content

Instantly share code, notes, and snippets.

@abdullahbutt
Created January 28, 2014 14:17
Show Gist options
  • Select an option

  • Save abdullahbutt/8668484 to your computer and use it in GitHub Desktop.

Select an option

Save abdullahbutt/8668484 to your computer and use it in GitHub Desktop.
get variables in php get_defined_vars()
<?php
$variables=get_defined_vars();
foreach($variables as $keys=>$val)
{
echo "$".$keys."=null;"."<br/>";
}
/*
Since get_defined_vars() only gets the variables at the point you call the function, there is a simple way to get the variables defined within the current scope.
*/
// The very top of your php script
$vars = get_defined_vars();
// Now do your stuff
$foo = 'foo';
$bar = 'bar';
// Get all the variables defined in current scope
$vars = array_diff(get_defined_vars(),$vars);
echo '<pre>';
print_r($vars);
echo '</pre>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment