-1

I recently came across a function defined as follows:

function *functionname* (&$parameter1, &$parameter, $parameter3)

Could someone tell me what does the & mean in front of $parameter1 and $parameter2 please? Thanks for your help!

Qirel
  • 25,449
  • 7
  • 45
  • 62
Veritas
  • 3
  • 4
  • [PHP Docs](http://www.php.net/manual/en/functions.arguments.php#functions.arguments.by-reference) and "Passing Arguments by Reference" – Mark Baker Mar 09 '17 at 10:08

3 Answers3

0

That means passing by reference.

ref: http://php.net/manual/en/language.references.pass.php

Normally, PHP is a pass by value but if you wish to perform pass by reference you can do the &$var

<?php
function foo(&$var)
{
    $var++;
}
function bar() // Note the missing &
{
    $a = 5;
    return $a;
}
foo(bar()); // Produces fatal error as of PHP 5.0.5, strict standards notice
            // as of PHP 5.1.1, and notice as of PHP 7.0.0

foo($a = 5); // Expression, not variable
foo(5); // Produces fatal error
?>
User1911
  • 394
  • 1
  • 5
  • 22
0

http://php.net/manual/en/functions.arguments.php

To have an argument to a function always passed by reference, prepend an ampersand (&) to the argument name in the function definition:

Ghilas BELHADJ
  • 13,412
  • 10
  • 59
  • 99
0

You are assigning that array value by reference.

passing argument through reference (&$) and by $ is that when you pass argument through reference you work on original variable, means if you change it inside your function it's going to be changed outside of it as well, if you pass argument as a copy, function creates copy instance of this variable, and work on this copy, so if you change it in the function it won't be changed outside of it

Reference php

Bilal Ahmed
  • 4,005
  • 3
  • 22
  • 42