Skip to content

Instantly share code, notes, and snippets.

@StolenThunda
Created February 26, 2019 04:36
Show Gist options
  • Save StolenThunda/02eb28c05c13da3c14fdeca9f2fad887 to your computer and use it in GitHub Desktop.
Save StolenThunda/02eb28c05c13da3c14fdeca9f2fad887 to your computer and use it in GitHub Desktop.
Get list of all user-defined vars
<?php
// list of keys to ignore (including the name of this variable)
$ignore = array('GLOBALS', '_FILES', '_COOKIE', '_POST', '_GET', '_SERVER', '_ENV', 'ignore');
// diff the ignore list as keys after merging any missing ones with the defined list
$vars = array_diff_key(get_defined_vars() + array_flip($ignore), array_flip($ignore));
// should be left with the user defined var(s) (in this case $testVar)
var_dump($vars);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment