1) When an array is passed as an argument to a method or function, is it passed by reference, or by value?
2) When assigning an array to a variable, is the new variable a reference to the original array, or is it new copy?
What about doing this:
$a = array(1,2,3);
$b = $a;
Is $b a reference to $a?
For the second part of your question, see the array page of the manual, which states (quoting) :
And the given example :
For the first part, the best way to be sure is to try 😉
Consider this example of code :
It’ll give this output :
Which indicates the function has not modified the “outside” array that was passed as a parameter : it’s passed as a copy, and not a reference.
If you want it passed by reference, you’ll have to modify the function, this way :
And the output will become :
As, this time, the array has been passed “by reference”.
Don’t hesitate to read the References Explained section of the manual : it should answer some of your questions 😉