Syntax : array_merge(array1, array2...): array
The array_merge() function merges the elements of one or more arrays into a single resultant array in such a way, So that the values of one array append to the end of previous ones. We can pass one or more arrays as parameters.
Example :
<?php
$array1 = array(1, 'a' => "white", 10, 'b' => "apple");
$array2 = array('a' => "red", 2, 'xyz', 4, 'b' => "apple");
$result = array_merge($array1, $array2);
print_r($result);
?>
Output :
Array ( [0] => 1 [a] => red [1] => 10 [b] => apple [2] => 2 [3] => xyz [4] => 4 )
Note :
Syntax : array_combine(array $keys, array $values): array
The array_combine() function creates an array by using the elements from one “keys” array and one “values” array.
While passing two arrays in the function, make sure the number of elements in both the arrays are equal, otherwise it will return an error.
Example :
<?php
$name=array("Ikhlaque Ahmed","Raheel","Subhan");
$age=array("35","29","10");
$combine_array = array_combine($name,$age);
print_r($combine_array);
?>
Output :
Array ( [Ikhlaque Ahmed] => 35 [Raheel] => 37 [Subhan] => 43 )
We learn today array_merge vs array_combine. This is most asking question on PHP interview. This article will help you to understand better about differences between array_merge vs array_combine.
Introduction In the world of web development, selecting the correct framework is critical. Laravel and…
Introduction By enabling containerization, Docker has transformed the way software is built, deployed, and managed.…
Introduction Speed and efficiency are critical in the ever-changing world of web development. Effective caching…
Introduction Git, a popular version control system in software development, enables developers to track changes,…
Introduction Are you tired of grappling with tangled changes and unfinished work while using Git?…
Introduction Version control is essential in software development because it ensures that changes to a…