What is the difference between array_merge and array_combine functions in PHP?
The main difference between array_merge and array_combine functions in PHP is that array_merge merges two or more arrays into a single array, while array_combine creates a new array by using one array for keys and another for its values. To merge two arrays using array_merge:
$array1 = [1, 2, 3];
$array2 = [4, 5, 6];
$mergedArray = array_merge($array1, $array2);
print_r($mergedArray);
```
To combine two arrays using array_combine:
```php
$keys = ['a', 'b', 'c'];
$values = [1, 2, 3];
$combinedArray = array_combine($keys, $values);
print_r($combinedArray);
Keywords
Related Questions
- What are the best practices for reading values from external files in PHP scripts to avoid conflicts?
- How can PHP scripts be optimized to restrict access to certain LDAP user groups?
- What are the best practices for handling database queries and results in PHP to ensure compatibility with different PHP versions?