I want to use values in an array as independent arguments in a function call. Example:
// Values \"a\" and \"b\"
$arr = array(\"alpha\", \"beta\");
// ... ar
This question is fairly old but there is finally more direct support for this in PHP 5.6+:
http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list.new
$arr = array("alpha", "beta");
my_func(...$arr);
if I understand you correctly:
$arr = array("alpha", "beta");
call_user_func_array('my_func', $arr);
You can do that using call_user_func_array(). It works wonders (and even with lambda functions since PHP 5.3).
try list()
// Values "a" and "b"
$arr = array("alpha", "beta");
list($a, $b) = $arr;
my_func($a, $b);
function my_func($a,$b=NULL) { echo "{$a} - {$b}"; }