What are some best practices for ensuring proper array manipulation in PHP functions?

When manipulating arrays in PHP functions, it is important to ensure that the array is passed by reference if you want to modify it directly. This can be achieved by using the `&` symbol before the parameter in the function definition. Additionally, it is good practice to check if the array is empty or if the key exists before performing any manipulation to avoid errors.

// Example of a PHP function manipulating an array properly
function manipulateArray(&$array) {
    if (!empty($array) && isset($array['key'])) {
        $array['key'] = 'new value';
    }
}

// Usage of the function
$data = ['key' => 'old value'];
manipulateArray($data);
print_r($data); // Output: Array([key] => new value)