Is there away to pass a variable (with array data) into a function without having to use as a parameter each time I want to use the function?
My situation is that I have producing UI elements for a form. Right now if I define the input's name I get the field which works as designed, but I also have to pass two variables every time.
Function Defined:
function getDecision($name,$game,$answer) {
// lots of code not very relevant
}
Ideally I want to pass the $game
and $answer
variables inside the function for what is dependent on them. I am using code igniter and the $game
variable is passed to the view on load of the page. The $answer
variable can be defined within function only if the $game
has been passed or define.
Current use of the function:
getDecision('company_name', $game, $answer);
Ideal use of function (simpler use):
getDecision('company_name');
Let me know if there is anything else I need to define, I don't want to show all of the code because there is nearly 100 lines of code.