How can PHP be used to display all variables of another script without knowing the variables beforehand?
To display all variables of another script without knowing them beforehand, we can use the `get_defined_vars()` function in PHP. This function returns an array containing all defined variables in the current scope, including variables from the included script. By using this function, we can dynamically display all variables without needing to know their names in advance.
// Include the script whose variables we want to display
include 'script.php';
// Get all defined variables
$variables = get_defined_vars();
// Display all variables
foreach ($variables as $key => $value) {
echo $key . ' = ' . $value . '<br>';
}