Created
January 28, 2014 14:17
-
-
Save abdullahbutt/8668484 to your computer and use it in GitHub Desktop.
get variables in php get_defined_vars()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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