Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

call_user_func_array

Calls a function, passing the arguments as an array.

Syntax

call_user_func_array(callable $callback, array $args): mixed

Parameters

ParameterTypeDescription
$callbackcallableA function or a method.
$argsarrayThe arguments; string keys become named arguments.

Return value

mixedThe result of the called function.

Examples

Arguments from an array:

<?php
 
echo call_user_func_array('max', [3, 9, 4]), "\n";
echo call_user_func_array('str_pad', ['7', 3, 'pad_string' => '0', 'pad_type' => STR_PAD_LEFT]);

Output:

9
007

Notes

The same is usually written more briefly: max(...$numbers).

See also

In the tutorial

  • More about functions — Named arguments, variable-length argument lists, passing by reference, static variables and recursion in PHP.

Thanks for reading!

Donate to the site — we work hard for you.