2

Here is the code I've found on the web:

$array = [1, 2, 3];
echo implode(',', $array), "\n";

foreach ($array as &$value) {}    // by reference
echo implode(',', $array), "\n";

foreach ($array as $value) {}     // by value (i.e., copy)
echo implode(',', $array), "\n";

I want to understand why this happens. Can someone explain what happens with the reference each step. I know about this "bug" but I want to understand why is this happening.

BTW The output is:

1,2,3
1,2,3
1,2,2
TIGER
  • 2,864
  • 5
  • 35
  • 45
Spown1962
  • 39
  • 5

0 Answers0