What is the potential issue with using call-by-reference in PHP functions for arrays?

When using call-by-reference in PHP functions for arrays, the original array can be modified unintentionally within the function, leading to unexpected behavior. To avoid this issue, it is recommended to pass arrays by value instead of by reference when working with functions to ensure that the original array remains unchanged.

<?php

// Function that takes an array by value to avoid unintended modifications
function modifyArray(array $arr) {
    // Modify the array here
    $arr[] = "new element";
    
    // Return the modified array
    return $arr;
}

// Original array
$originalArray = [1, 2, 3];

// Call the function with the original array
$modifiedArray = modifyArray($originalArray);

// Output the original and modified arrays
print_r($originalArray);
print_r($modifiedArray);