I'm looking for the best way to do what this probably can't do until the future:
// Only one of these, different each time
$arg_string = "'arg1', 'arg2', 'arg3'"; // Unknown number of arguments!
$arg_string = "'arg1', 'arg2', 'arg3', 'arg4'"; // Unknown number of arguments!
$arg_string = "'arg1'"; // Unknown number of arguments!
// Where I need help
$stmt->execute([$arg_string]); // Wish I could, maybe PHP 9 will
My problem is that a $string or $array can't be easily passed to a function() as its parameters.
This is important for my work because I am creating a method to query the database and I may have an unknown number of columns or values. This is what the code will look like just before using exec().
I found this SO article (PHP use variable to pass multiple arguments to function) which discusses call_user_func_array(). But, I can't figure out how to use call_user_func_array() with execute(). Even if I were to guess, I still would want to know what is best.
I don't mind turning $arg_string into an array first, or not, whatever is best.
What is the best way to do what this can't:
$stmt->execute([$arg_string]);