Search code examples
phpfunction-parameter

How to pass a string with a few comma separated values as function parameters


For instance:

$str = '1, 2, 4, 13';

I'd like the effect to be as if it were:

func(1, 2, 4, 13)

Solution

  • $params = explode(', ', $str);
    call_user_func_array("func", $params);