Example: array_merge
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php //Example of array_merge $firstarray=array("vasanthan"=>"software engineer","nazar"=>"Team Lead"); $secondarray=array("vasanthan"=>"Web Designer","Sreejith"=>"Project Manager"); $merge_result=array_merge($firstarray,$secondarray); print_r($merge_result); //Ouput will be like as below /*Array ( [vasanthan] => Web Designer [nazar] => Team Lead [Sreejith] => Project Manager )*/ ?> |
here i used the same key for the both arrays. in firstarray i used “vasanthan” as key second array again used “vasanthan” as key. in output second array key is override the first array key.
Example array_combine
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php //Example of array_combine $firstarray=array("vasanthan","nazar"); $secondarray=array("Software engineer","Project Manager"); $merge_result=array_combine($firstarray,$secondarray); print_r($merge_result); //Ouput will be like as below /* Array ( [vasanthan] => Software engineer [nazar] => Project Manager ) */ ?> |
In array_combine first array values as key and the second array values as value in the result array.