Mostafa Talebi
Mostafa Talebi

Reputation: 9183

Pass-by-reference for functions with varying length of functions

I have a function with optional number of arguments, something like this:

function DoSomething()
{
    $args = funct_get_args();

    // and the rest of function
}

In the function above, how can I define the first argument to be passed by reference?

So when I calling it, I be able to do so:

DoSomething(&$first, $second, $third);

Upvotes: 0

Views: 56

Answers (1)

hindmost
hindmost

Reputation: 7195

Simply declare it in the parameter list:

function DoSomething(&$first) {
    $args = func_get_args();
    // and the rest of function
}

DoSomething($first, $second, $third);

Upvotes: 4

Related Questions