What is difference between Array combine() and Array merge()?
Array_combine(): To Combines the elements of two arrays and Returns
the New Array.The new Array keys are the values of First Array values
and the new array values are Second array values.
Array_combine()Example:
<?php
$arr=array(1,2,50);
$arr1=array(452,672,542);
print_r(array_combine($arr,$arr1));
?>
Output:
Array
(
[1] => 452
[2] => 672
[50] => 542
)
Array_merge(): merges two or more Arrays as New Array.
Array_merge() Example:
<?php
$arr=array(101,301,501);
$arr1=array(451,671,541);
print_r(array_merge($arr,$arr1));
?>
output:
Array
(
[0] => 101
[1] => 301
[2] => 501
[3] => 451
[4] => 671
[5] => 541
)
Array_combine()Example:
<?php
$arr=array(1,2,50);
$arr1=array(452,672,542);
print_r(array_combine($arr,$arr1));
?>
Output:
Array
(
[1] => 452
[2] => 672
[50] => 542
)
Array_merge(): merges two or more Arrays as New Array.
Array_merge() Example:
<?php
$arr=array(101,301,501);
$arr1=array(451,671,541);
print_r(array_merge($arr,$arr1));
?>
output:
Array
(
[0] => 101
[1] => 301
[2] => 501
[3] => 451
[4] => 671
[5] => 541
)
Comments
Post a Comment