Page 1 of 1
Offer function, that returns variable's name.
Posted: Sun Jul 27, 2008 10:45 pm
by sholerov
Hi!
For example, there is a script:
<?
echo some_function ($foobarbaz);
?>
This script returns string "foobarbaz".
What's the proper name of "some_function"?
Thanks!
Re: Offer function, that returns variable's name.
Posted: Mon Jul 28, 2008 1:54 am
by jaoudestudios
You can call the function whatever you want, as long as it is the same name when you define it!
i.e.
Code: Select all
echo function1($var);
function function1($v) {
// do something
return $v;
}
Re: Offer function, that returns variable's name.
Posted: Mon Jul 28, 2008 6:10 am
by EverLearning
Take a look at
get_defined_vars function.
You'd call it from inside of your function to get the passed arguments.
Code: Select all
test(4, 5, 6);
function test($first, $second, $third) {
var_dump(get_defined_vars());
}
And you get
Code: Select all
array
'first' => int 4
'second' => int 5
'third' => int 6
Is that what you wanted?