Skip to main content

Posts

Showing posts with the label PHP Functions

PHP Functions - array_merge() and array_combine()

PHP has lots of built-in functions. So that you may not remember all the the functions. Among those functions, array_merge and array_combine are 2 very useful php functions that are very useful for core php programmer.

array_merge() function: array_merge() is a built-in php function that is used to merge two or more arrays in one place. Unlike array_combine, it does not need equal number of elements in the each array. Here is a simple example of array_merge();

Example <?php
$data1 = array("id"=>"21","name"=>"RKA","contact"=>"9843XXXXXX");
$data2 = array("address"=>"Kathmandu, Nepal");
$arrayMerge = array_merge($data1,$data2);
print_r($arrayMerge);

?>
Output Array ( [id] => 21 [name] => RKA [contact] => 9843XXXXXX [address] => Kathmandu, Nepal )

array_combine() function: 
array_combine() is also a built-in php function which is used for combine only 2 arrays. And both the array …