What are the advantages and disadvantages of using references in PHP programming?

When using references in PHP programming, the main advantage is that it allows for more efficient memory usage and can help improve performance by avoiding unnecessary copying of variables. However, references can also make code harder to read and understand, as they can lead to unexpected behavior if not used carefully.

// Example of using references in PHP
$var1 = 5;
$var2 = &$var1; // $var2 is now a reference to $var1

echo $var1; // Output: 5
echo $var2; // Output: 5

$var1 = 10;

echo $var1; // Output: 10
echo $var2; // Output: 10