In PHP, how do I copy arrays with built-in functions?

In PHP, you can easily copy arrays using built-in functions. Here are a couple of methods to achieve this:

1. Using `array_merge()`: This function merges one or more arrays. If the arrays have the same string keys, the later value will overwrite the previous one.

2. Using `array_slice()`: This function returns a sequence of the array elements, allowing you to create a copy of a specific section of the array.


        // Example of copying an array using array_merge
        $originalArray = [1, 2, 3];
        $copiedArray = array_merge([], $originalArray);
        print_r($copiedArray);

        // Example of copying an array using array_slice
        $originalArray = [1, 2, 3, 4, 5];
        $copiedArray = array_slice($originalArray, 0, count($originalArray));
        print_r($copiedArray);
    

PHP array copy PHP arrays built-in functions array methods