Forum Moderators: coopster
my_function($field, field)
Am I stuck with needing to use both arguments, or is there any way that I can just use one argument (field), and that the function can then be structured to get the actual value of $field from the script where that value is defined?
Or is there just no way that a function can use variables that are defined in the script (other than as a function argument)?
For example if I have
$color= "red";
So the variable color has the value of red. Is there anyway to extract the actual variable name from $color? (I just want the 'color' part) So that I could finally have something like:
$y = "color";
my_function($field_name) {
$field_value = $_GLOBALS[$field_name]; // get value of field variable
// sample function action
echo '$'. $field_name .' contains the value: '. $field_value;
return;
// end sample
}
Now say you have $j, that has the value 5.
The following:
my_function('j');
Prints out:
"$j contains the value: 5"
---------------------------
I'm confused what the purpose is of the function, but the code above would help you get the variable value with just the variable name alone.