PHP array return array vs passing as reference I'm not sure if Code Review is the proper SE site. If not, please point me in the right direction.

Let's assume we have a simple function, where you can pass an array and it will do some work on it. For simplicity sake, let's just assume you pass an array of integers to the function and it doubles them

I was wondering what's the correct way to do this, either by passing an array, and returning that array, which is AFAIK a pass by value in PHP and finally overwriting the initial variable, or simply passing a reference to that array.

Option 1, pass by value:

public function doubleValue(array $input): array
{
    foreach ($input as $key=&gt;$val) {
        $input[$key] += $val;
    }

    return $input;
}

// called as $foo = $someClass-&gt;doubleValue($foo);


Option 2, pass by reference:

public function doubleValue(array &amp;$input): void
{
    foreach ($input as $key=&gt;$val) {
        $input[$key] += $val;
    }
}

// called as $someClass-&gt;doubleValue($foo);


My assumption would be, that pass by reference has to be faster, as it doesn't need to copy the array to that function, copy it back and assign it to the variable, but I could be wrong (at least ex. the built in sort function works this way). Are there any metrics about it? What is the recommended approach?
Just never return an argument by reference. It is nearly as bad as using global. And even a memory management is not an excuse. In case your array is big, create a function that does the calculations, and then apply it to each element inside of an explicit loop.