Multiple choice technology web 2.0

How do you pass a variable by value?

  1. \$a = &\$b
  2. $a = &b
  3. $a = *$b
  4. $a = $b
Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In PHP, assignment with $a = $b creates a copy of the value, which is passing by value. The & operator creates a reference to the original variable instead of copying it. Options A and B both use the reference operator &, while option C uses invalid syntax.

AI explanation

In PHP, prepending an ampersand (&) to a variable in an assignment, as in $a = &$b, makes $a a reference to $b — they then share the same underlying value, which is pass-by-reference behavior. Plain assignment, $a = $b, copies the value of $b into $a, so later changes to $b do not affect $a. That plain-copy form is what 'by value' means, so $a = $b is the correct answer.