What are the advantages of using global variables in PHP functions for array manipulation?
Using global variables in PHP functions for array manipulation can make the code more concise and easier to read by reducing the need to pass arrays as parameters to functions. It can also simplify the process of accessing and modifying arrays within multiple functions. However, it is important to use global variables carefully to avoid potential conflicts or unintended side effects in the code.
<?php
$myArray = [1, 2, 3, 4, 5];
function addToMyArray($value) {
global $myArray;
$myArray[] = $value;
}
addToMyArray(6);
print_r($myArray);
?>