Home > database >  In php, is there a way to populate a functions arguements from a list of strings?
In php, is there a way to populate a functions arguements from a list of strings?

Time:11-03

For example, if I have an array:

$indicators = ['open','high','low','close'];

Is it possible use these a function parameters without hardcoding them into the function?

customFunction($open,$high,$low,$close);

CodePudding user response:

You are probably looking for the spread syntax operator i.e.

customFunction(...$indicators);

CodePudding user response:

If you can't use the spread operator, you could also use call_user_func_array:

call_user_func_array('customFunction', $indicators);
  •  Tags:  
  • php
  • Related