If you need to print result of the function, for example:
function result(){
return "res";
}
Use print_r(result());
-> print_r(). You'll get res
at the output.
Your function must return something, it could be an object, an array, a string or numeric value, boolean also. In this case you'll see the output in print_r()
for each type of data or in echo()
for string/numeric values.
In your case use
print_r($_GET["z"]);
Use of quotes means print some string. "z"
- means index of array in variable $_GET
.
Also, read the difference between using of single and double quotes.
Also, you can put an output value of the function into variable and then print it, but datatype of this output must be string/numeric.
function result(){
// return 333;
return "eeee";
}
$s = result();
print_r("$s");
// Output is: eeee (or 333)
Demo
In case of array variable you can use print_r()
in the way you are:
$_GET["a"] = "word";
print_r("$_GET[a]");
// Output is: word
But $_GET["a"]
should has also only string/numeric datatype.
Here you can read about many cases of string parsing process.
In case of print() function you can use it as:
$_GET['x'] = 'sss';
print "this is {$_GET['x']} !";
Again, value should has string/numeric datatype.
If you wanna get result from function, which presented as a string value you can use next code:
$_GET['z'] = "phpinfo()";
foreach ($_GET as $item){
if (gettype($item) === 'string'){
if (strpos($item,'()')) {
$s = str_replace('()','',$item);
print $s(); // execution
}
}
}
Here you can send the name of desired function as a string like "phpinfo()"
.
You cannot use ${phpinfo()}
in $_GET
because of that. It reads content and thinks that it's a variable, but it doesn't.