How can I get all variable names that have been used?
knnknn
11:36 pm on Aug 10, 2005 (gmt 0)
I want to get a list of all variable names that have been used in the script:
<?php $foo = 'blue'; $bar = 'red;
echo listofallvariablename(); ?>
Should create 'foo', 'bar'
Is there a function like that?
knnknn
11:51 pm on Aug 10, 2005 (gmt 0)
OK, case closed.
I can fetch all names via $GLOBALS or get_defined_vars()
coopster
3:14 am on Aug 12, 2005 (gmt 0)
Bingo. Just be careful when you look at your data if you are running the function from inside a user-defined function. Variable scope may come into play here! Example:
<pre> <?php function checkVariables() { $a = 1; print "Within the function:\n"; print_r(get_defined_vars()); } $b = 2; checkVariables(); print "Outside the function:\n"; print_r(get_defined_vars()); ?> </pre>