I want to display a variable or an array by passing the variable name to a function and display it without having to use the dangerous eval()
function. I am having trouble making it happen. Is it possible to do?
Here's the code:
show( '$_SESSION', 'a' ); // it does not work
show( '_SESSION', 'a' ); // it does not work
function show( $showWhat = null, $showType = null ) {
echo '<pre>';
if( strtolower( $showType ) == 'a' ) { // 'a' represents array()'s
print_r( '$' . $showWhat ); // it does not work
print_r( $showWhat ); // it does not work
}
else { // 'v' represents variables
echo $showWhat;
}
echo '</pre>';
exit;
}