fork download
  1. <?php
  2. // The path into the array
  3. $GET_VARIABLE = "a.b.c";
  4. // Some example data
  5. $GLOBALS["a"]= array("b"=>array("c"=>"foo"));
  6.  
  7. // Construct an accessor into the array
  8. $variablePath = explode( ".", $GET_VARIABLE );
  9. $accessor = implode( "' ][ '", $variablePath );
  10. $variable = "\$GLOBALS[ '". $accessor . "' ]";
  11.  
  12. // Print the value for debugging purposes (this works fine)
  13. echo $GLOBALS["a"]["b"]["c"] . "\n";
  14. // Try to evaluate the accessor (this will fail)
  15. echo $$variable;
  16. ?>
Success #stdin #stdout #stderr 0.01s 20520KB
stdin
Standard input is empty
stdout
    foo
stderr
PHP Notice:  Undefined variable: $GLOBALS[ 'a' ][ 'b' ][ 'c' ] in /home/OLi3xu/prog.php on line 15