create an associative array that contains the integer or string.
VARIABLE_NAME is the name of the variable that you want to pass to the function
$offset_array[0] = $VARIABLE_NAME
use the Key, value combination in PHP for an array. Key is the name of the variable
value is the value of the associated key (see else statement in the code below)
here is the complete code:
// store variable in an array
$offset_array[0] = $VARIABLE_NAME;
// call the function
return_input( $offset_array );
function return_input( $offset_array )
{
// if passed item is an integer, return the integer
if( is_int($offset_array[0] )
return $offset_array[0];
// else return the variable name
else
{
// loop through the array, return the index of the integer (the variable name)
foreach ($offset_array as $key=>$value)
{
// key is now the name of the variable, the index
return $key;
}
}
}